﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using web.core.ViewModels;
using web.core.Models;
using web.component;
using System.Configuration;
using System.IO;
using System.Xml.Serialization;
using System.Text;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;
using System.Runtime.InteropServices.ComTypes;

namespace web.core.Controllers
{
    public class profileController : baseController
    {
        public ActionResult profile_search()
        {
            InitPage();
            return View();
        }

        public ActionResult list_employee_family()
        {
            InitPage();
            return View();
        }

        public ActionResult list_employee_medical_records()
        {
            InitPage();
            return View();
        }

        public ActionResult list_employee_house_land()
        {
            InitPage();
            return View();
        }

        public ActionResult list_employee_job_severance()
        {
            InitPage();
            return View();
        }

        public ActionResult list_employee_visa_passport()
        {
            InitPage();
            return View();
        }

        public ActionResult list_employee_rotation()
        {
            InitPage();
            return View();
        }

        public ActionResult list_employee_school()
        {
            InitPage();
            return View();
        }

        public ActionResult list_employee_foreign_countries()
        {
            InitPage();
            return View();
        }

        public ActionResult list_employee_insurance()
        {
            InitPage();
            return View();
        }

        public ActionResult list_employee_contract()
        {
            InitPage();
            return View();
        }
    
        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_list_employee(int? id, string text_search, string option_search, int? department_id, byte? employee_status, DateTime? birth_day, int? b_day, int? b_month, int? b_year, string study_level, bool? join_dang, string blood_group, string current_address, int? start_date_insurance, string positions, string house_land_status, string foreign_language, int? date_join, bool? gender, int? army_join, string ranks, int? school_id, string marital_status)
        {
            return control_list_employee(id ?? 1, 10, text_search, option_search, department_id, employee_status, birth_day, b_day, b_month, b_year, study_level, join_dang, blood_group, current_address, start_date_insurance, positions, house_land_status, foreign_language, date_join, gender, army_join, ranks, school_id, marital_status);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_list_employee(int? id, int? pagesize, string text_search, string option_search, int? department_id, byte? employee_status, DateTime? birth_day, int? b_day, int? b_month, int? b_year, string study_level, bool? join_dang, string blood_group, string current_address, int? start_date_insurance, string positions, string house_land_status, string foreign_language, int? date_join, bool? gender, int? army_join, string ranks, int? school_id, string marital_status)
        {
            List<SelectListItem> sizeDrop = new List<SelectListItem>();
            sizeDrop.AddRange(new SelectListItem[] { 
                            new SelectListItem{Selected=pagesize==10?true:false, Text = "10", Value = "10" },
                            new SelectListItem{Selected=pagesize==25?true:false, Text = "25", Value = "25" },
                            new SelectListItem{Selected=pagesize==50?true:false, Text = "50", Value = "50" },
                            new SelectListItem{Selected=pagesize==100?true:false, Text = "100", Value = "100" }
                        });

            List<SelectListItem> listOption = new List<SelectListItem>();
            listOption.AddRange(new SelectListItem[] { 
                            new SelectListItem{Selected=true, Text = "Tất cả", Value = "all" },
                            new SelectListItem{Selected=false, Text = "Mã nhân viên", Value = "employee_code" },
                            new SelectListItem{Selected=false, Text = "Tên nhân viên", Value = "full_name" }
                        });

            string type_list_employee = ParentActionName;

            if (type_list_employee.Contains(conts_global.Employee_Family))
            {
                type_list_employee = conts_global.Employee_Family;
            }
            if (type_list_employee.Contains(conts_global.Employee_School))
            {
                type_list_employee = conts_global.Employee_School;
            }
            else if (type_list_employee.Contains(conts_global.Employee_Foreign_Countries))
            {
                type_list_employee = conts_global.Employee_Foreign_Countries;
            }
            else if (type_list_employee.Contains(conts_global.Employee_House_Land))
            {
                type_list_employee = conts_global.Employee_House_Land;
            }
            else if (type_list_employee.Contains(conts_global.Employee_Insurance))
            {
                type_list_employee = conts_global.Employee_Insurance;
            }
            else if (type_list_employee.Contains(conts_global.Employee_Job_Severance))
            {
                type_list_employee = conts_global.Employee_Job_Severance;
            }
            else if (type_list_employee.Contains(conts_global.Employee_Medical_Records))
            {
                type_list_employee = conts_global.Employee_Medical_Records;
            }
            else if (type_list_employee.Contains(conts_global.Employee_Rotation))
            {
                type_list_employee = conts_global.Employee_Rotation;
            }
            else if (type_list_employee.Contains(conts_global.Employee_School))
            {
                type_list_employee = conts_global.Employee_School;
            }
            else if (type_list_employee.Contains(conts_global.Employee_Visa_Passport))
            {
                type_list_employee = conts_global.Employee_Visa_Passport;
            }
            else if (type_list_employee.Contains(conts_global.Employee_Contract))
            {
                type_list_employee = conts_global.Employee_Contract;
            }
            id = id ?? 1;
            int total_record=0;
            var page_view = new ViewModels.PageListEmployeeViewModels();
            page_view.list_option_search = listOption;
            page_view.list_pagesize = sizeDrop;
            page_view.pagesize = pagesize ?? 10;
            page_view.option_search = option_search;
            page_view.type_list_employee = type_list_employee;
            page_view.page_list_employee = Models.profileModels.getPageListEmployee(id ?? 1, pagesize ?? 10, text_search ?? null, option_search, department_id, employee_status, birth_day, b_day, b_month, b_year, join_dang, study_level, blood_group, current_address, start_date_insurance, positions, foreign_language, house_land_status, date_join, type_list_employee, ref total_record, gender, army_join, ranks, school_id, marital_status);
            page_view.list_department = Models.profileModels.getListDepartment();
            page_view.list_school = Models.h_contentModels.getListSchool();
            page_view.department_id = department_id;
            page_view.employee_status=employee_status;
            page_view.birth_day=birth_day;
            page_view.b_day = b_day;
            page_view.b_month = b_month;
            page_view.b_year = b_year;
            page_view.join_dang=join_dang;
            page_view.study_level=study_level;
            page_view.blood_group=blood_group;
            page_view.current_address=current_address;
            page_view.start_date_insurance=start_date_insurance;
            page_view.positions=positions;
            page_view.foreign_language=foreign_language;
            page_view.house_land_status=house_land_status;
            page_view.date_join=date_join;
            page_view.army_join = army_join;
            page_view.ranks = ranks;
            page_view.marital_status = marital_status;
            page_view.school_id = 
            page_view.total_record = total_record;
            page_view.gender = gender;
            return PartialView("../Shared/control_list_employee", page_view);
        }

        public ActionResult list_employee_export(int? type, int? id, int? pagesize, string text_search, string option_search, int? department_id, byte? employee_status, DateTime? birth_day, int? b_day, int? b_month, int? b_year, string study_level, bool? join_dang, string blood_group, string current_address, int? start_date_insurance, string positions, string house_land_status, string foreign_language, int? date_join, bool? gender, int? army_join, string ranks, int? school_id, string marital_status)
        {

            Document document = new Document(PageSize.A4, 40, 40, 40, 40);
            string type_list_employee = "";

            
            id = id ?? 1;
            int total_record = 0;
            var page_list_employee = Models.profileModels.getPageListEmployee(id ?? 1, pagesize ?? 10, text_search ?? null, option_search, department_id, employee_status, birth_day, b_day, b_month, b_year, join_dang, study_level, blood_group, current_address, start_date_insurance, positions, foreign_language, house_land_status, date_join, type_list_employee, ref total_record, gender, army_join, ranks, school_id, marital_status);
             var page_list_departments_by_employee = Models.profileModels.getListDepartmentsByEmployee(id ?? 1);
            Response.Clear();
            if (type == 1)
            {
                //export to excel
                Response.AddHeader("Content-Disposition", "attachment; filename=Danh_sach_nhan_vien_" + DateTime.Now.Year + ".xls");
                Response.ContentType = "application/ms-excel";
            }
            else if (type == 2)
            {
                //export to word
                Response.AddHeader("Content-Disposition", "attachment; filename=Danh_sach_nhan_vien_" + DateTime.Now.Year + ".doc");
                Response.ContentType = "application/ms-word";
            }
            else if (type == 3)
            {
                //export to pdf
                Response.AddHeader("content-disposition", "attachment; filename=Danh_sach_nhan_vien_" + DateTime.Now.Year + ".pdf");
                Response.ContentType = "application/octet-stream";
                PdfWriter.GetInstance(document, Response.OutputStream);
                document.Open();
            }

            Response.Charset = string.Empty;
            Response.ContentEncoding = Encoding.Unicode;
            Response.BinaryWrite(Encoding.Unicode.GetPreamble());
            StringBuilder sb = new StringBuilder();
            sb.Append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"padding:0px;margin:0px;width:27.7cm\" >");
                            sb.Append("<tr>");
                            sb.Append("<td colspan=\"6\" style=\"text-align:left;font-weight:bold;padding-bottom:10px;\">");
                            sb.Append("Công ty ADCC");
                            sb.Append("</td>");
                            sb.Append("</tr>");
                            sb.Append("<tr>");
                            sb.Append("<td colspan=\"6\" style=\"text-align:center;text-transform:uppercase;font-weight:bold;\" >DANH SÁCH NHÂN VIÊN</td>");
                            sb.Append("</tr>");
                           
                            sb.Append("<tr>");
                            sb.Append("<td style=\"border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;border-top:1px dotted #ccc;border-left:1px dotted #ccc;text-align:center;width:80px;\">STT<br/></td>")
                            .Append("<td style=\"border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;text-align:center;border-top:1px dotted #ccc;width:350px;\">Mã NV<br/></td>")
                            .Append("<td style=\"border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;text-align:center;border-top:1px dotted #ccc;width:200px;\">Họ và tên</td>")
                            .Append("<td style=\"border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;text-align:center;border-top:1px dotted #ccc;width:200px;\">Ngày sinh</td>")
                            .Append("<td style=\"border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;text-align:center;border-top:1px dotted #ccc;width:200px;\">Phòng ban</td>")
                            .Append("<td style=\"border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;text-align:center;border-top:1px dotted #ccc;width:250px;\">Chức vụ</td>");
                            sb.Append("</tr>");
                            for (int i = 0; i < page_list_employee.Count; i++)
                            {
                                var index = i + 1;
                                sb.Append("<tr>");
                                sb.Append("<td style=\"border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;text-align:center;border-left:1px dotted #ccc;\">" + index + "</td>");
                                sb.Append("<td style=\"border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;text-align:center;\">" + page_list_employee[i].employee_code + "</td>");
                                sb.Append("<td style=\"border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;text-align:center;\">" + page_list_employee[i].full_name + "</td>");
                                sb.Append("<td style=\"border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;text-align:center;\">" + String.Format("{0:dd/MM/yyyy}",page_list_employee[i].birth_day) + "</td>");
                                sb.Append("<td style=\"border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;text-align:center;\">" + page_list_departments_by_employee[i].departments_name + "</td>");
                                sb.Append("<td style=\"border-right:1px dotted #ccc;border-bottom:1px dotted #ccc;text-align:center;\">" + page_list_employee[i].ranks + "</td>");
                                sb.Append("</tr>");
                            }
                            string test = sb.ToString();
                            //sb.Append("<tr><td colspan=\"6\" style=\"text-transform:uppercase;padding-top:20px;padding-left:20px;text-align:left;\">Nhân viên thống kê</td></tr>");
                            //sb.Append("<tr><td colspan=\"6\" style=\"text-transform:uppercase;padding-top:-20px;position: relative;text-align:right;padding-right:20px;\">Nhân viên chính trị</td></tr>");
            sb.Append("</table>");

            if (type == 3)
            {
                StringReader str = new StringReader(sb.ToString());
                HTMLWorker htmlworker = new HTMLWorker(document);
                htmlworker.Parse(str);
                Response.Flush();
                Response.Close();
                document.Close();
                Response.Write(document);
            }
            else
            {
                Response.Write(sb.ToString());
            }
            Response.End();

            return RedirectToAction("profile_search", new { id = 1, pagesize = pagesize, text_search = text_search, option_search = option_search, department_id = department_id, employee_status = employee_status, birth_day = birth_day, join_dang = join_dang, study_level = study_level, blood_group = blood_group, current_address = current_address, start_date_insurance = start_date_insurance, positions = positions, foreign_language = foreign_language, house_land_status = house_land_status, date_join = date_join, type_list_employee = type_list_employee });
        }

        public ActionResult detail_profile()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        public ActionResult control_detail_profile(int? id)
        {
            var detail_view = new ViewModels.DetailProfileViewModels();
            var employee = profileModels.getEmployeeByID(id ?? 0);
            if (employee != null)
            {
                detail_view.employee_detail = employee;
                detail_view.list_employee_family = profileModels.getListEmployeeFamilyByEmployee(employee.employee_id);
                //detail_view.list_employee_house_land = profileModels.getListEmployeeHouseLandByEmployee(employee.employee_id);
                detail_view.list_employee_insurance = profileModels.getListEmployeeInsuranceByEmployee(employee.employee_id);
                detail_view.list_employee_job_severance = profileModels.getListEmployeeJobSeveranceByEmployee(employee.employee_id);
                detail_view.list_employee_medical_records = profileModels.getListEmployeeMedicalRecodByEmployee(employee.employee_id);
                detail_view.list_employee_rotation = profileModels.getListEmployeeRotationByEmployee(employee.employee_id);
                detail_view.list_employee_school = profileModels.getListEmployeeSchoolByEmployee(employee.employee_id);
                detail_view.list_employee_visa_passport = profileModels.getListEmployeeVisaPassportByEmployee(employee.employee_id);
                detail_view.list_contract = profileModels.getListContractByEmployee(employee.employee_id);
            }
           
            return PartialView("../Shared/control_detail_profile", detail_view);
        }

        public ActionResult detail_profile_pdf(int? id)
        {
            var detail_view = new ViewModels.DetailProfileViewModels();
            var employee = profileModels.getEmployeeByID(id ?? 0);
            detail_view.employee_detail = employee;
            detail_view.list_employee_family = profileModels.getListEmployeeFamilyByEmployee(employee.employee_id);
            //detail_view.list_employee_house_land = profileModels.getListEmployeeHouseLandByEmployee(employee.employee_id);
            detail_view.list_employee_insurance = profileModels.getListEmployeeInsuranceByEmployee(employee.employee_id);
            detail_view.list_employee_job_severance = profileModels.getListEmployeeJobSeveranceByEmployee(employee.employee_id);
            detail_view.list_employee_medical_records = profileModels.getListEmployeeMedicalRecodByEmployee(employee.employee_id);
            detail_view.list_employee_rotation = profileModels.getListEmployeeRotationByEmployee(employee.employee_id);
            detail_view.list_employee_school = profileModels.getListEmployeeSchoolByEmployee(employee.employee_id);
            detail_view.list_employee_visa_passport = profileModels.getListEmployeeVisaPassportByEmployee(employee.employee_id);
            detail_view.list_contract = profileModels.getListContractByEmployee(employee.employee_id);
            return ViewPdf(detail_view);
        }

        public ActionResult detail_profile_export(int? type, int? id)
        {

            Document document = new Document(PageSize.A4, 40, 40, 40, 40);
            var employee = profileModels.getEmployeeByID(id ?? 0);
            var contact = profileModels.getLastContractByEmployee(employee.employee_id);
            var employee_school = profileModels.getListEmployeeSchoolByEmployee(employee.employee_id).OrderBy(p=>p.school_id).FirstOrDefault();
            
            var list_employee_school = profileModels.getListEmployeeSchoolByEmployee(employee.employee_id).OrderBy(p => p.school_id).ToList();
            var list_employee_rotation = profileModels.getListEmployeeRotationByEmployee(employee.employee_id);
            var employee_insurance = profileModels.getListEmployeeInsuranceByEmployee(employee.employee_id).OrderBy(p=>p.insurance_id).FirstOrDefault();
            var list_employee_family = profileModels.getListEmployeeFamily(employee.employee_id);
            var list_employee_foreign_country=profileModels.getListEmployeeForeignCountryByEmployee(employee.employee_id);
            var employee_visa_passport = profileModels.getListEmployeeVisaPassportByEmployee(employee.employee_id).OrderByDescending(p=>p.passport_id).FirstOrDefault();
            var employee_mediacal = profileModels.getListEmployeeMedicalRecodByEmployee(employee.employee_id).OrderByDescending(p => p.medical_records_id).FirstOrDefault();
            Response.Clear();
            if (type == 1)
            {
                //export to excel
                Response.AddHeader("Content-Disposition", "attachment; filename=ho_so_" + employee.full_name + ".xls");
                Response.ContentType = "application/ms-excel";
            }
            else if (type == 2)
            {
                //export to word
                Response.AddHeader("Content-Disposition", "attachment; filename=ho_so_" + employee.full_name + ".doc");
                Response.ContentType = "application/ms-word";
            }
            else if (type == 3)
            {
                //export to pdf
                Response.AddHeader("content-disposition", "attachment; filename=ho_so_" + employee.full_name + ".pdf");
                Response.ContentType = "application/octet-stream";
                PdfWriter.GetInstance(document, Response.OutputStream);
                document.Open();
            }
            var gender = "";
            var unit="";
            var school_name="";
            var time_in_school = "";
            var day_join="";
            var month_join="";
            var year_join="";
            var majors="";
            var school_result="";
            var diplomas="";
            var passport_number="";
            var passport_issuing_date="";
            var enable_start = "";
            var enable_end = "";
            var medical_status = "";
            var blood_group = "";
            var major_disease = "";
            var number_insurance_book = "";
            var insurance_start_date = "";
            var type_contract_name = "";
            var house = "";
            var signature_date = "";
            var marital = "";
            var department = "";
            if (id != null) {
                department = profileModels.getTopOneDepartmentsByEmployee(id ?? 0)!=null?profileModels.getTopOneDepartmentsByEmployee(id ?? 0).departments_name:"";
            }

            if(!string.IsNullOrEmpty(employee.house_land_status))
            {
                if (employee.house_land_status == "1") { house = "Được cấp đất và mua nhà của quân đội"; }
                else if (employee.house_land_status == "2") { house = "Mua bên ngoài"; }
                else if (employee.house_land_status == "3") { house = "Đất của gia đình"; }
                else if (employee.house_land_status == "4") { house = "Đi thuê"; }
                else { house = " "; }
            }
            if (!string.IsNullOrEmpty(employee.marital_status))
            {
                house = employee.marital_status;
            }
            if (employee.gender != null)
            {
                if (employee.gender == true) { gender = "Nam"; } else { gender = "Nữ"; }
            } 

            //if(employee.unit!=null)
            //{
            //    if(employee.unit==1){unit="Chính quyền";}
            //    else if(employee.unit==2){unit="Tổ chức Đảng";}
            //    else if(employee.unit==3){unit="Tổ chức quần chúng";}
            //    else{unit=" ";}
            //}

            if (employee_school != null)
            {
                if (employee_school.school_id != null) { var sc = profileModels.getSchoolByID(employee_school.school_id ?? 0); school_name = sc.school_name; }

                if (employee_school.start_date != null && employee_school.end_date != null)
                {
                    time_in_school = (employee_school.end_date.Value.Year - employee_school.start_date.Value.Year).ToString() + " năm";
                }

                majors = employee_school.majors ?? " ";

                school_result = employee_school.descriptions ?? " ";

                diplomas = employee_school.diplomas ?? " ";
            }

            if(employee_visa_passport!=null)
            {
                passport_number = employee_visa_passport.passport_number ?? " ";

                passport_issuing_date = String.Format("{0:dd/MM/yyyy}", employee_visa_passport.passport_issuing_date);

                enable_start= String.Format("{0:dd/MM/yyyy}", employee_visa_passport.enable_start);

                enable_end = String.Format("{0:dd/MM/yyyy}", employee_visa_passport.enable_end);
            }

            if(employee_mediacal!=null)
            {
                medical_status = employee_mediacal.medical_status ?? " ";
                blood_group = employee_mediacal.blood_group ?? " ";
                major_disease=employee_mediacal.major_disease ?? " ";
            }

            if (employee_insurance != null)
            {
                number_insurance_book = employee_insurance.number_insurance_book ?? " ";
                insurance_start_date = String.Format("{0:dd/MM/yyyy}", employee_insurance.start_date);
            }

            if(employee.date_join!=null)
            {
                day_join=employee.date_join.Value.Day.ToString();
                month_join=employee.date_join.Value.Month.ToString();
                year_join=employee.date_join.Value.Year.ToString();
            }

            if(contact!=null)
            {
                if (contact.type_contract_id != null)
                {
                    var type_contract = profileModels.getTypeContractByID(contact.type_contract_id ?? 0);
                    if (type_contract != null)
                    {
                        type_contract_name = type_contract.type_contract_name;
                    }
                }

                if (contact.signature_date != null)
                {
                    signature_date = String.Format("{0:dd/MM/yyyy}", contact.signature_date);
                }
            }
            

            Response.Charset = string.Empty;
            Response.ContentEncoding = Encoding.Unicode;
            Response.BinaryWrite(Encoding.Unicode.GetPreamble());
            StringBuilder sb = new StringBuilder();
            sb.Append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"639\" style=\"padding:0px;margin:0px;\" >");
            sb.Append("<tr>");
            
            if (employee.avarta != null)
            {
                String strUrl = HttpContext.Server.MapPath("~" + employee.avarta);
                sb.Append("<td colspan=\"5\"><img alt='' src='" + strUrl + "' style=\"width:113px;height:151px\" width=\"113\" height=\"151\"/></td>");
            }
            sb.Append("<td width=\"439\" colspan=\"12\"  ><p align=\"center\">&nbsp;");
            sb.Append("<p align=\"center\">THÔNG TIN CHI TIẾT NHÂN VIÊN&nbsp;<strong><br/>" + employee.full_name.ToUpper() + "<br /><br /></strong></p>");
            sb.Append("</td>");
            sb.Append("</tr>");
            
            
            
            
            
            sb.Append("<tr>");
            sb.Append("<td width=\"120\"  style=\"padding-left:5px;padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333\">Mã NV: "+employee.employee_code??" "+" </td>");
            sb.Append("<td width=\"198\" colspan=\"6\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333\">Họ tên:<br /><strong>" + employee.full_name??" " + "</strong></p></td>");
            sb.Append("<td width=\"124\" colspan=\"6\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333\"> Giới tính: " + gender + " </td>");
            sb.Append("<td width=\"196\" colspan=\"4\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;border-top:1px dotted #333\"> Ngày sinh: " + String.Format("{0:dd/MM/yyyy}", employee.birth_day) + " </td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"120\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Ngày nhập ngũ: </td>");
            sb.Append("<td width=\"198\" colspan=\"6\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > " + String.Format("{0:dd/MM/yyyy}", employee.army_join) + " </td>");
            sb.Append("<td width=\"124\" colspan=\"6\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Ngày tuyển dụng: </td>");
            sb.Append("<td width=\"196\" colspan=\"4\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > "+String.Format("{0:dd/MM/yyyy}", employee.date_join)+" </td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"318\" colspan=\"7\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Ngày ký HĐLĐ:&nbsp; " + signature_date + " </td>");
            sb.Append("<td width=\"320\" colspan=\"10\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" >&nbsp;  </td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"318\" colspan=\"7\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Cấp bậc :    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+employee.ranks+" </td>");
            sb.Append("<td width=\"320\" colspan=\"10\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Hệ số lương: "+employee.salary_coefficient??" "+" </td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"639\" colspan=\"17\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" >&nbsp;  </td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"234\" colspan=\"5\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Chức vụ: &nbsp;" + employee.positions + "</td>");
            sb.Append("<td width=\"405\" colspan=\"12\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Đơn vị: " + department + " </td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"639\" colspan=\"17\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Quê quán: " + employee.hometown??" " + "</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"639\" colspan=\"17\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Chỗ ở hiện nay: " + employee.current_address??" " + "</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"639\" colspan=\"17\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Hộ khẩu thường trú: " + employee.household_registration??" " + "</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"639\" colspan=\"17\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\"> Số điện thoại di động: "+employee.mobile+" | Điện thoại cố định : "+employee.phone+"</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"639\" colspan=\"17\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Email liên lạc: "+employee.email+"</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"318\" colspan=\"7\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Ngày vào đoàn: " + String.Format("{0:dd/MM/yyyy}", employee.dateIn_doan) + " </td>");
            sb.Append("<td width=\"320\" colspan=\"10\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Ngày vào Đảng: " + String.Format("{0:dd/MM/yyyy}", employee.dateIn_dang) + " </td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"318\" colspan=\"7\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Tình trạng hôn nhân: " + marital + " </td>");
            sb.Append("<td width=\"152\" colspan=\"8\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Dân tộc: " + employee.ethnic??" " + " </td>");
            sb.Append("<td width=\"168\" colspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Tôn giáo : " + employee.religion??" " + " </td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"318\" colspan=\"7\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Số hiệu Sỹ quan: " + employee.serial_number_officer??" " + " </td>");
            sb.Append("<td width=\"320\" colspan=\"10\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\"> Số hiệu Quân nhân: " + employee.serial_number_military??" " + " </td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"318\" colspan=\"7\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Số CMND: " + employee.identity_card??" " + " </td>");
            sb.Append("<td width=\"320\" colspan=\"10\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Ngày cấp : " + String.Format("{0:dd/MM/yyyy}", employee.issuing_date) + "- Nơi cấp: " + employee.place_of_issue +" </td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"318\" colspan=\"7\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Số CM Quân đội : " + employee.army_identity_card??" " + " </td>");
            sb.Append("<td width=\"320\" colspan=\"10\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Ngày cấp : " + String.Format("{0:dd/MM/yyyy}", employee.army_issuing_date) + "- Nơi cấp: " + employee.place_of_issue + " </td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"318\" colspan=\"7\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Trình độ văn hóa: " + employee.cultural_level??" " + "</td>");
            sb.Append("<td width=\"320\" colspan=\"10\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Trình độ Ngoại ngữ:" +employee.foreign_language+ "</td>");
            sb.Append("</tr>");
            //sb.Append("<tr>");
            //sb.Append("<td width=\"318\" colspan=\"7\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\"> Qua trường: " + school_name + " </td>");
            //sb.Append("<td width=\"320\" colspan=\"10\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\"  > Ngành học : " + majors + "</td>");
            //sb.Append("</tr>");
            //sb.Append("<tr>");
            //sb.Append("<td width=\"318\" colspan=\"7\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Thời gian: " + time_in_school + " </td>");
            //sb.Append("<td width=\"152\" colspan=\"7\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Kết quả : " + school_result + " </td>");
            //sb.Append("<td width=\"168\" colspan=\"3\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Văn bằng: " + diplomas + " </td>");
            //sb.Append("</tr>");
            //sb.Append("<tr>");
            //sb.Append("<td width=\"639\" colspan=\"17\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" >&nbsp;  </td>");
            //sb.Append("</tr>");
            //bat dau qua trinh hoc van
            sb.Append("<tr>");
            sb.Append("<td width=\"639\" colspan=\"17\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px solid #333;border-right:1px dotted #333\" > <strong>Quá trình đào tạo: </strong></p></td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"225\" colspan=\"4\" style=\"padding-left:5px;border-left:1px solid #333;border-bottom:1px dotted #333;text-align:center;\" >Thời gian </td>");
            sb.Append("<td width=\"189\" colspan=\"7\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;text-align:center;\" >Trường đào tạo</td>");
            sb.Append("<td width=\"94\" colspan=\"5\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;text-align:center;\" >Khóa học/Chuyên ngành </td>");
            sb.Append("<td width=\"161\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px solid #333;text-align:center;\" >Cấp học/Bằng cấp(kếtquả)</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"130\" colspan=\"2\" style=\"padding-left:5px;border-left:1px solid #333;border-bottom:1px dotted #333\" ><p align=\"center\">Từ </p></td>");
            sb.Append("<td width=\"95\" colspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\" ><p align=\"center\">Đến </p></td>");
            sb.Append("</tr>");
            foreach (var sh in list_employee_school)
            {
                var sh_start_date = "";
                sh_start_date = String.Format("{0:dd/MM/yyyy}", sh.start_date);
                var sh_end_date = "";
                if (sh.end_date == null)
                {
                    sh_end_date = "Đến nay";
                }
                else {
                    sh_end_date = String.Format("{0:dd/MM/yyyy}", sh.end_date);
                }
                web.data.entities.school employee_shool_type = null;
                if (sh != null)
                {
                    employee_shool_type = h_contentModels.getSchoolByID(sh.employee_school_id);
                }
                var cm = sh.courses + "<br/>" + sh.majors;
                var cn = sh.study_level + "<br/>" + sh.diplomas;
                sb.Append("<tr>");
                sb.Append("<td width=\"95\" colspan=\"2\" style=\"padding-left:5px;border-left:1px solid #333;border-bottom:1px dotted #333\" > " + sh_start_date + " </td>");
                sb.Append("<td width=\"95\" colspan=\"2\" style=\"padding-left:5px;border-left:1px solid #333;border-bottom:1px dotted #333\" > " + sh_end_date + " </td>");
                sb.Append("<td width=\"189\" colspan=\"7\" style=\"padding-left:5px;border-left:1px solid #333;border-bottom:1px dotted #333\" >&nbsp; " + employee_shool_type.school_name ?? " " + "  </td>");
                sb.Append("<td width=\"94\" colspan=\"5\" style=\"padding-left:5px;border-left:1px solid #333;border-bottom:1px dotted #333\" >&nbsp; " + cm + " </td>");
                sb.Append("<td width=\"161\" style=\"padding-left:5px;border-left:1px solid #333;border-bottom:1px dotted #333;border-right:1px solid #333\" >&nbsp;" + cn + "  </td>");
                sb.Append("</tr>");
            }
            //kethuc hoc van
           

            sb.Append("<tr>");
            sb.Append("<td width=\"639\" colspan=\"17\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px solid #333;border-right:1px solid #333\" >&nbsp; </p></td>");
            sb.Append("</tr>");

            sb.Append("<tr>");
            sb.Append("<td width=\"639\" colspan=\"17\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px solid #333;border-right:1px solid #333\" > <strong>Quá trình công tác: </strong></p></td>");
            sb.Append("</tr>");

            sb.Append("<tr>");
            sb.Append("<td width=\"225\" colspan=\"4\" style=\"padding-left:5px;border-left:1px solid #333;border-bottom:1px solid #333;text-align:center;\" >Thời gian </td>");
            sb.Append("<td width=\"189\" colspan=\"7\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px solid #333;border-bottom:1px solid #333;text-align:center;\" >Chức vụ, đơn vị ( ghi từ cấp Đội, Xưởng trở lên ) </td>");
            sb.Append("<td width=\"94\" colspan=\"5\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px solid #333;border-bottom:1px solid #333;text-align:center;\" >Cấp bậc <br />(tháng, năm) </td>");
            sb.Append("<td width=\"161\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px solid #333;border-bottom:1px solid #333;border-right:1px solid #333;text-align:center;\" >Đoàn thể</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"95\" colspan=\"2\" style=\"padding-left:5px;border-left:1px solid #333;border-bottom:1px solid #333\" ><p align=\"center\">Từ </p></td>");
            sb.Append("<td width=\"95\" colspan=\"2\" style=\"padding-left:5px;border-left:1px solid #333;border-bottom:1px solid #333;\" ><p align=\"center\">Đến </p></td>");
            sb.Append("</tr>");
            foreach (var employee_rotation in list_employee_rotation)
            {
                //var unit_rotation="";
                //if(employee_rotation.unit!=null)
                //{
                //    if(employee_rotation.unit==1){unit_rotation="Chính quyền";}
                //    else if(employee_rotation.unit==2){unit_rotation="Tổ chức Đảng";}
                //    else if(employee_rotation.unit==3){unit_rotation="Tổ chức quần chúng";}
                //    else{unit_rotation=" ";}
                //}
                string depart = "";
                var de = profileModels.getDepartmentByID(employee_rotation.departments_id ?? 0);
                if (de != null)
                {
                    if (!string.IsNullOrEmpty(de.departments_name))
                    {
                        depart = employee_rotation.positions + "<br/>" + de.departments_name;
                    }
                }
                string dennay = "";

                if (employee_rotation.to_date != null)
                {
                    dennay = String.Format("{0:dd/MM/yyyy}", employee_rotation.to_date);
                }
                else
                {
                    dennay = "Đến nay";
                }
                sb.Append("<tr>");
                sb.Append("<td width=\"95\" colspan=\"2\" style=\"padding-left:5px;border-left:1px solid #333;border-bottom:1px dotted #333\" > " + String.Format("{0:dd/MM/yyyy}", employee_rotation.from_date) + " </td>");
                sb.Append("<td width=\"95\" colspan=\"2\" style=\"padding-left:5px;border-left:1px solid #333;border-bottom:1px dotted #333\" > " + String.Format("{0:dd/MM/yyyy}", dennay) + " </td>");
                sb.Append("<td width=\"189\" colspan=\"7\" style=\"padding-left:5px;float:left;border-left:1px solid #333;border-bottom:1px dotted #333\" >" + depart ?? " " + "  </td>");
                sb.Append("<td width=\"94\" colspan=\"5\" style=\"padding-left:5px;border-left:1px solid #333;border-bottom:1px dotted #333\" >&nbsp; " + employee_rotation.levels ?? " " + " </td>");
                sb.Append("<td width=\"161\" style=\"padding-left:5px;border-left:1px solid #333;border-bottom:1px dotted #333;border-right:1px solid #333\" >&nbsp;" + employee_rotation.unit ?? " " + "  </td>");
                sb.Append("</tr>");
                
            }
            sb.Append(" <td width=\"639\" colspan=\"17\" style=\"padding-left:5px;border-left:1px solid #333;border-bottom:1px solid #333;border-right:1px solid #333\" >&nbsp;  </td>");
            sb.Append("</tr>");
            
            sb.Append("<tr>");
            sb.Append("<td width=\"639\" colspan=\"17\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\"> Về công ty từ " + day_join + " tháng "+month_join+" năm "+year_join+" </td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"346\" colspan=\"10\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Số sổ bảo hiểm: " + number_insurance_book + " </td>");
            sb.Append("<td width=\"293\" colspan=\"7\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Thời gian đóng BHXH: " + insurance_start_date + "</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"346\" colspan=\"10\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Khen thưởng(hình thức): </td>");
            sb.Append("<td width=\"293\" colspan=\"7\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Ngày tháng khen: </td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"346\" colspan=\"10\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Kỷ luật(Hình thức): </td>");
            sb.Append("<td width=\"293\" colspan=\"7\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Ngày tháng kỷ luật: </td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"639\" colspan=\"17\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Tình hình nhà ở : " + house + " </td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"639\" colspan=\"17\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" >&nbsp;  </td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"639\" colspan=\"17\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > <strong>Thành phần gia đình:</strong></p></td>");
            sb.Append("</tr>");
            foreach (var family in list_employee_family)
            {
                
                if (family.obj_family != null)
                {
                    //(1:Vợ,2:Bố,3:Mẹ,4:Chồng,5:Bố chồng,6:Mẹ chồng,7:Bố vợ,8:Mẹ vợ,9:Con ruột,10:Anh chị em ruột)
                    if(family.obj_family==1)
                    {
                        //Vợ
                        sb.Append("<tr>");
                        sb.Append("<td width=\"252\" colspan=\"6\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > <strong>Họ tên vợ</strong>: "+family.fullname??" " +" </td>");
                        sb.Append("<td width=\"171\" colspan=\"6\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Sinh năm : "+ family.birth_day +" </td>");
                        sb.Append("<td width=\"216\" colspan=\"5\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Nghề nghiệp : "+family.job??" "+" </td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                        sb.Append("<td width=\"639\" colspan=\"17\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Quê quán: "+family.hometown??" "+"</td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                        sb.Append("<td width=\"639\" colspan=\"17\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\"> Chỗ ở hiện nay: "+family.current_address??" "+" </td>");
                        sb.Append("</tr>");
                    }
                    else if (family.obj_family == 4)
                    {
                        //chồng
                        sb.Append("<tr>");
                        sb.Append("<td width=\"252\" colspan=\"6\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > <strong>Họ tên chồng</strong>: " + family.fullname ?? " " + " </td>");
                        sb.Append("<td width=\"171\" colspan=\"6\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Sinh năm : " + family.birth_day + " </td>");
                        sb.Append("<td width=\"216\" colspan=\"5\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Nghề nghiệp : " + family.job ?? " " + " </td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                        sb.Append("<td width=\"639\" colspan=\"17\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Quê quán: " + family.hometown ?? " " + "</td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                        sb.Append("<td width=\"639\" colspan=\"17\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\"> Chỗ ở hiện nay: " + family.current_address ?? " " + " </td>");
                        sb.Append("</tr>");
                    }
                    else if (family.obj_family == 2)
                    {
                        //bố
                        sb.Append("<tr>");
                        sb.Append("<td width=\"252\" colspan=\"6\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > <strong>Họ tên bố đẻ</strong>: " + family.fullname ?? " " + " </td>");
                        sb.Append("<td width=\"171\" colspan=\"6\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Sinh năm : " + family.birth_day + " </td>");
                        sb.Append("<td width=\"216\" colspan=\"5\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Nghề nghiệp : " + family.job ?? " " + " </td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                        sb.Append("<td width=\"639\" colspan=\"17\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Quê quán: " + family.hometown ?? " " + "</td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                        sb.Append("<td width=\"639\" colspan=\"17\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\"> Chỗ ở hiện nay: " + family.current_address ?? " " + " </td>");
                        sb.Append("</tr>");
                    }
                    else if (family.obj_family == 3)
                    {
                        //mẹ
                        sb.Append("<tr>");
                        sb.Append("<td width=\"252\" colspan=\"6\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > <strong>Họ tên mẹ đẻ</strong>: " + family.fullname ?? " " + " </td>");
                        sb.Append("<td width=\"171\" colspan=\"6\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Sinh năm : " + family.birth_day + " </td>");
                        sb.Append("<td width=\"216\" colspan=\"5\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Nghề nghiệp : " + family.job ?? " " + " </td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                        sb.Append("<td width=\"639\" colspan=\"17\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Quê quán: " + family.hometown ?? " " + "</td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                        sb.Append("<td width=\"639\" colspan=\"17\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\"> Chỗ ở hiện nay: " + family.current_address ?? " " + " </td>");
                        sb.Append("</tr>");
                    }
                    else if (family.obj_family == 5 && employee.gender==false)
                    {
                        //bố chồng
                        sb.Append("<tr>");
                        sb.Append("<td width=\"252\" colspan=\"6\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > <strong>Họ tên bố chồng</strong>: " + family.fullname ?? " " + " </td>");
                        sb.Append("<td width=\"171\" colspan=\"6\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Sinh năm : " + family.birth_day + " </td>");
                        sb.Append("<td width=\"216\" colspan=\"5\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Nghề nghiệp : " + family.job ?? " " + " </td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                        sb.Append("<td width=\"639\" colspan=\"17\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Quê quán: " + family.hometown ?? " " + "</td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                        sb.Append("<td width=\"639\" colspan=\"17\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\"> Chỗ ở hiện nay: " + family.current_address ?? " " + " </td>");
                        sb.Append("</tr>");
                    }
                    else if (family.obj_family == 6 && employee.gender == false)
                    {
                        //mẹ chồng
                        sb.Append("<tr>");
                        sb.Append("<td width=\"252\" colspan=\"6\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > <strong>Họ tên mẹ chồng</strong>: " + family.fullname ?? " " + " </td>");
                        sb.Append("<td width=\"171\" colspan=\"6\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Sinh năm : " + family.birth_day + " </td>");
                        sb.Append("<td width=\"216\" colspan=\"5\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Nghề nghiệp : " + family.job ?? " " + " </td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                        sb.Append("<td width=\"639\" colspan=\"17\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Quê quán: " + family.hometown ?? " " + "</td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                        sb.Append("<td width=\"639\" colspan=\"17\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\"> Chỗ ở hiện nay: " + family.current_address ?? " " + " </td>");
                        sb.Append("</tr>");
                    }
                    else if (family.obj_family == 7 && employee.gender == true)
                    {
                        //bố vợ
                        sb.Append("<tr>");
                        sb.Append("<td width=\"252\" colspan=\"6\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > <strong>Họ tên bố vợ</strong>: " + family.fullname ?? " " + " </td>");
                        sb.Append("<td width=\"171\" colspan=\"6\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Sinh năm : " + family.birth_day + " </td>");
                        sb.Append("<td width=\"216\" colspan=\"5\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Nghề nghiệp : " + family.job ?? " " + " </td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                        sb.Append("<td width=\"639\" colspan=\"17\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Quê quán: " + family.hometown ?? " " + "</td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                        sb.Append("<td width=\"639\" colspan=\"17\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\"> Chỗ ở hiện nay: " + family.current_address ?? " " + " </td>");
                        sb.Append("</tr>");
                    }
                    else if (family.obj_family == 8 && employee.gender == true)
                    {
                        //mẹ vợ
                        sb.Append("<tr>");
                        sb.Append("<td width=\"252\" colspan=\"6\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > <strong>Họ tên mẹ vợ</strong>: " + family.fullname ?? " " + " </td>");
                        sb.Append("<td width=\"171\" colspan=\"6\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Sinh năm : " + family.birth_day + " </td>");
                        sb.Append("<td width=\"216\" colspan=\"5\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Nghề nghiệp : " + family.job ?? " " + " </td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                        sb.Append("<td width=\"639\" colspan=\"17\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Quê quán: " + family.hometown ?? " " + "</td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                        sb.Append("<td width=\"639\" colspan=\"17\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\"> Chỗ ở hiện nay: " + family.current_address ?? " " + " </td>");
                        sb.Append("</tr>");
                    }
                    else if (family.obj_family == 9)
                    {
                        //con ruột
                        sb.Append("<tr>");
                        sb.Append("<td width=\"252\" colspan=\"6\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > <strong>Họ tên con</strong>: " + family.fullname ?? " " + " </td>");
                        sb.Append("<td width=\"171\" colspan=\"6\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Sinh năm : " + family.birth_day + " </td>");
                        sb.Append("<td width=\"216\" colspan=\"5\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Nghề nghiệp : " + family.job ?? " " + " </td>");
                        sb.Append("</tr>");
                    }
                    else if (family.obj_family == 10)
                    {
                        //anh chị em ruột
                        sb.Append("<tr>");
                        sb.Append("<td width=\"639\" colspan=\"17\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > <strong>Họ tên anh chị em ruột : </strong> "+family.fullname??" "+" </td>");
                        sb.Append("</tr>");
                        sb.Append("<tr>");
                        sb.Append("<td width=\"327\" colspan=\"8\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Nghề nghiệp : "+ family.job??" " +"</td>");
                        sb.Append("<td width=\"311\" colspan=\"9\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Sinh năm : "+ family.birth_day +"</td>");
                        sb.Append("</tr>");
                    }
                }
                
            }
            sb.Append("<tr>");
            sb.Append("<td width=\"639\" colspan=\"17\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" >&nbsp;  </td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"639\" colspan=\"17\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Đã đi ra nước ngoài nào: ");
            foreach(var foreign in list_employee_foreign_country)
            {
                sb.Append(""+foreign.country??" "+"&nbsp;<em>("+String.Format("{0:dd/MM/yyyy}",foreign.out_date)+")</em>&nbsp; | ");
            }
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("<td width=\"328\" colspan=\"9\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\"> Số passport : " + passport_number + " &nbsp;&nbsp;&nbsp;&nbsp; </td>");
            sb.Append("<td width=\"311\" colspan=\"8\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Ngày cấp : " + passport_issuing_date + " </td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"328\" colspan=\"9\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\"> Ngày hiệu lực : " + enable_start + " </td>");
            sb.Append("<td width=\"311\" colspan=\"8\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\"> Ngày hết hạn: " + enable_end + " </td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"164\" colspan=\"3\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Sức khỏe loại: " + medical_status + " </td>");
            sb.Append("<td width=\"164\" colspan=\"6\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Nhóm máu: " + blood_group + " </td>");
            sb.Append("<td width=\"311\" colspan=\"8\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" > Bệnh chính: " + major_disease + " </td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"164\" colspan=\"3\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Hợp đồng lao động : </td>");
            sb.Append("<td width=\"475\" colspan=\"14\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\"  > " + type_contract_name + " </td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"164\" colspan=\"3\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > Mô tả chi tiết : </td>");
            sb.Append("<td width=\"475\" colspan=\"14\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\"  > " + employee.description_detail + " </td>");
            sb.Append("</tr>");

            sb.Append("</table>");

            if (type == 3)
            {
                StringReader str = new StringReader(sb.ToString());
                HTMLWorker htmlworker = new HTMLWorker(document);
                htmlworker.Parse(str);
                Response.Flush();
                Response.Close();
                document.Close();
                Response.Write(document);
            }
            else
            {
                Response.Write(sb.ToString());
            }
            Response.End();

            return RedirectToAction("detail_profile", employee.employee_id);
        }

        //Danh sach QNCN_CNVQP
        public ActionResult list_QNCN_CNVQP()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_list_QNCN_CNVQP(DateTime? from_date, DateTime? to_date, int? id, string text_search, string option_search, int? department_id, byte? employee_status,int? type_report)
        {
            from_date = DateTime.Now.AddMonths(-6);
            to_date = DateTime.Now;
            return control_list_QNCN_CNVQP(from_date, to_date, id ?? 1, 10, text_search, option_search, department_id, employee_status, type_report);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_list_QNCN_CNVQP(DateTime? from_date, DateTime? to_date, int? id, int? pagesize, string text_search, string option_search, int? department_id, byte? employee_status, int? type_report)
        {
            if (to_date > DateTime.Now)
            {
                to_date = DateTime.Now;
            }
             var QNCN_CNVQP_view = new ViewModels.DetailProfileViewModels();
             TryUpdateModel(QNCN_CNVQP_view);
            List<SelectListItem> sizeDrop = new List<SelectListItem>();
            sizeDrop.AddRange(new SelectListItem[] { 
                            new SelectListItem{Selected=pagesize==10?true:false, Text = "10", Value = "10" },
                            new SelectListItem{Selected=pagesize==25?true:false, Text = "25", Value = "25" },
                            new SelectListItem{Selected=pagesize==50?true:false, Text = "50", Value = "50" },
                            new SelectListItem{Selected=pagesize==100?true:false, Text = "100", Value = "100" }
                        });
            id= id ?? 1;
            QNCN_CNVQP_view.list_pagesize = sizeDrop;
            QNCN_CNVQP_view.pagesize = pagesize ?? 10;
            QNCN_CNVQP_view.id = id;
            QNCN_CNVQP_view.type_report = type_report;
            QNCN_CNVQP_view.from_date = from_date;
            QNCN_CNVQP_view.to_date = to_date;
            QNCN_CNVQP_view.text_search = text_search;
            QNCN_CNVQP_view.page_list_QNCN_CNVQP = profileModels.getListEmployee_QNCN_CNVQP(id ?? 1, pagesize ?? 10, text_search, department_id, employee_status, from_date, to_date, type_report);
            return PartialView("../Shared/control_list_QNCN_CNVQP", QNCN_CNVQP_view);
        }

        public ActionResult list_QNCN_CNVQP_export(int? type, DateTime? from_date, DateTime? to_date, int? id, int? pagesize, string text_search, string option_search, int? department_id, byte? employee_status, int? type_report)
        {
            if (to_date > DateTime.Now)
            {
                to_date = DateTime.Now;
            }
            Document document = new Document(PageSize.A4, 40, 40, 40, 40);
            var page_list_employee = Models.profileModels.getListEmployee_QNCN_CNVQP_export(option_search, department_id, employee_status, from_date, to_date, type_report);
            var page_list_departments_by_employee = Models.profileModels.getListDepartmentsByEmployee(id ?? 1);
            Response.Clear();
            if (type == 1)
            {
                //export to excel
                Response.AddHeader("Content-Disposition", "attachment; filename=Danh_sach_quan_nhan_chuyen_nghiep_cong_nhan_vien_quoc_phong_" + DateTime.Now.Year + ".xls");
                Response.ContentType = "application/ms-excel";
            }
            else if (type == 2)
            {
                //export to word
                Response.AddHeader("Content-Disposition", "attachment; filename=Danh_sach_quan_nhan_chuyen_nghiep_cong_nhan_vien_quoc_phong_" + DateTime.Now.Year + ".doc");
                Response.ContentType = "application/ms-word";
            }
            else if (type == 3)
            {
                //export to pdf
                Response.AddHeader("content-disposition", "attachment; filename=Danh_sach_quan_nhan_chuyen_nghiep_cong_nhan_vien_quoc_phong_" + DateTime.Now.Year + ".pdf");
                Response.ContentType = "application/octet-stream";
                PdfWriter.GetInstance(document, Response.OutputStream);
                document.Open();
            }

            Response.Charset = string.Empty;
            Response.ContentEncoding = Encoding.Unicode;
            Response.BinaryWrite(Encoding.Unicode.GetPreamble());
            StringBuilder sb = new StringBuilder();
            sb.Append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"padding:0px;margin:0px;width:27.7cm\" >");

            sb.Append("<tr>");
            sb.Append("<td colspan=\"12\"  ><p align=\"left\">Đơn vị : Công ty ADCC");
            sb.Append("<p align=\"center\">DANH SÁCH QUÂN NHÂN CHUYÊN NGHIỆP, CÔNG NHÂN VIÊN QUỐC PHÒNG<br />");
            sb.Append("Tháng........./Năm.........<br /></strong></p></td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"120\"  style=\"padding-left:5px;padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333\">STT</td>");
            sb.Append("<td width=\"198\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333;width:460px\">- Họ tên <br/>-Ngày tháng năm sinh<br/>-Số hiệu</strong></p></td>");
            sb.Append("<td width=\"124\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333\">- Ngày vào quân đội <br/>-Theo chế độ</td>");
            sb.Append("<td width=\"124\"   style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333\"> - Cấp bậc<br/>-Chức vụ CNQNS đang làm<br/>-Tháng năm đảm nhận </td>");
            sb.Append("<td width=\"124\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333\"> Dân tộc, tôn giáo,<br/>-Trình độ văn hóa </td>");
            sb.Append("<td width=\"124\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333\">-Đảng<br/>-Đoàn<br/>-Sức khỏe </td>");
            sb.Append("<td width=\"124\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333\">-Giới tính<br/>-Tình trạng hôn nhân </td>");
            sb.Append("<td width=\"124\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333\">-Tháng,năm hưởng lương<br/>-Theo chế độ<br/>-Diện bố trí</td>");
            sb.Append("<td width=\"124\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333\">-Lương đang hưởng(hệ số)<br/>-Tháng,năm nhận </td>");
            sb.Append("<td width=\"124\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333\">-Trình độ ngành nghề liên quan đến chuyên nghiệp QS<br/>-Đơn vị</td>");
            sb.Append("<td width=\"124\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333\"> -Nơi thường trú </td>");
            sb.Append("<td width=\"196\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;border-top:1px dotted #333\"> Khen thưởng<br/>Kỷ luật </td>");
            sb.Append("</tr>");
            for (int i = 0; i < page_list_employee.Count; i++)
            {
                var khenthuong = "";
                var kyluat = "";
                if (page_list_employee[i].type_reward == 1)
                {
                    khenthuong = page_list_employee[i].reward_name;
                }
                else if (page_list_employee[i].type_reward == 3)
                {
                    kyluat = page_list_employee[i].reward_name;
                }
                sb.Append("<tr>");
                sb.Append("<td width=\"164\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > " + i + 1 + " </td>");
                sb.Append("<td width=\"164\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" > " + page_list_employee[i].full_name ?? " " + " <br/>- " + String.Format("{0:dd/MM/yyyy}", page_list_employee[i].birth_day) + "<br/>- " + page_list_employee[i].serial_number_military ?? " " + "</td>");
                sb.Append("<td width=\"164\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" >- " + String.Format("{0:dd/MM/yyyy}", page_list_employee[i].army_join) + "</td>");
                sb.Append("<td width=\"164\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" >- " + page_list_employee[i].ranks ?? " " + " <br/>- " + page_list_employee[i].positions ?? " " + " <br/>- </td>");
                sb.Append("<td width=\"164\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" >- " + page_list_employee[i].ethnic + ",<br/>- " + page_list_employee[i].religion + "<br/>- " + page_list_employee[i].cultural_level + " </td>");
                sb.Append("<td width=\"164\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" >- " + page_list_employee[i].dateIn_dang + "<br/>- " + page_list_employee[i].dateIn_doan + "<br/>- Suc khoe</td>");
                sb.Append("<td width=\"164\"  style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" >- " + page_list_employee[i].gender + "<br/>- " + page_list_employee[i].marital_status + "</td>");
                sb.Append("<td width=\"164\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" >- <br/> - <br/></td>");
                sb.Append("<td width=\"164\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" >- " + page_list_employee[i].salary_coefficient + "<br/>- </td>");
                sb.Append("<td width=\"164\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" >- " + page_list_departments_by_employee[i].departments_name + "</td>");
                sb.Append("<td width=\"164\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333\" >- " + page_list_employee[i].household_registration + "</td>");
                sb.Append("<td width=\"311\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\" >- " + khenthuong + "<br/>- " + kyluat + "</td>");
                sb.Append("</tr>");
            }

            //sb.Append("<tr><td colspan=\"9\" style=\"text-transform:uppercase;padding-top:20px;padding-left:20px;text-align:left;\">Nhân viên thống kê</td></tr>");
            //sb.Append("<tr><td colspan=\"9\" style=\"text-transform:uppercase;padding-top:-20px;position: relative;text-align:right;padding-right:20px;\">Nhân viên chính trị</td></tr>");
            sb.Append("</table>");

            if (type == 3)
            {
                StringReader str = new StringReader(sb.ToString());
                HTMLWorker htmlworker = new HTMLWorker(document);
                htmlworker.Parse(str);
                Response.Flush();
                Response.Close();
                document.Close();
                Response.Write(document);
            }
            else
            {
                Response.Write(sb.ToString());
            }
            Response.End();

            return RedirectToAction("list_QNCN_CNVQP", new { id = 1, pagesize = pagesize, option_search = option_search, department_id = department_id, employee_status = employee_status, from_date = from_date, to_date = to_date });
        }

        //Danh sach QNCN_CNVQP
        public ActionResult list_DG_CB_QH()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_list_DG_CB_QH(DateTime? from_date, DateTime? to_date, int? id, string text_search)
        {
            from_date = DateTime.Now.AddMonths(-6);
            to_date = DateTime.Now;
            return control_list_DG_CB_QH(from_date, to_date, id ?? 1, 10, text_search);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_list_DG_CB_QH(DateTime? from_date, DateTime? to_date, int? id, int? pagesize, string text_search)
        {
            if (to_date > DateTime.Now)
            {
                to_date = DateTime.Now;
            }
            var DG_CB_QH_view = new ViewModels.PageListDG_CB_QHViewModels();
            TryUpdateModel(DG_CB_QH_view);
            List<SelectListItem> sizeDrop = new List<SelectListItem>();
            sizeDrop.AddRange(new SelectListItem[] { 
                            new SelectListItem{Selected=pagesize==10?true:false, Text = "10", Value = "10" },
                            new SelectListItem{Selected=pagesize==25?true:false, Text = "25", Value = "25" },
                            new SelectListItem{Selected=pagesize==50?true:false, Text = "50", Value = "50" },
                            new SelectListItem{Selected=pagesize==100?true:false, Text = "100", Value = "100" }
                        });

            
            id = id ?? 1;
            DG_CB_QH_view.list_pagesize = sizeDrop;
            DG_CB_QH_view.pagesize = pagesize ?? 10;
            DG_CB_QH_view.id = id;
            DG_CB_QH_view.page_list_department = profileModels.getListEmployee_DG_CB_QH(id ?? 1, pagesize ?? 10, text_search, from_date, to_date);
            DG_CB_QH_view.text_search = text_search;
            return PartialView("../Shared/control_list_DG_CB_QH", DG_CB_QH_view);
        }

        public ActionResult list_DG_CB_QH_export(int? type, DateTime? from_date, DateTime? to_date, int? id, int? pagesize, string text_search)
        {
            if (to_date > DateTime.Now)
            {
                to_date = DateTime.Now;
            }
            Document document = new Document(PageSize.A4, 10, 40, 20, 40);
            var page_list_department = profileModels.getListEmployee_DG_CB_QH_export(text_search, from_date, to_date);
            Response.Clear();
            if (type == 1)
            {
                //export to excel
                Response.AddHeader("Content-Disposition", "attachment; filename=Dien_giai_cap_bac_quan_ham_" + DateTime.Now.Year + ".xls");
                Response.ContentType = "application/ms-excel";
            }
            else if (type == 2)
            {
                //export to word
                Response.AddHeader("Content-Disposition", "attachment; filename=Dien_giai_cap_bac_quan_ham_" + DateTime.Now.Year + ".doc");
                Response.ContentType = "application/ms-word";
            }
            else if (type == 3)
            {
                //export to pdf
                Response.AddHeader("content-disposition", "attachment; filename=Dien_giai_cap_bac_quan_ham_" + DateTime.Now.Year + ".pdf");
                Response.ContentType = "application/octet-stream";
                PdfWriter.GetInstance(document, Response.OutputStream);
                document.Open();
            }

            Response.Charset = string.Empty;
            Response.ContentEncoding = Encoding.Unicode;
            Response.BinaryWrite(Encoding.Unicode.GetPreamble());
            StringBuilder sb = new StringBuilder();
            sb.Append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"padding:0px;margin:0px;width:27.7cm\" >");
            sb.Append("<tr>");
            sb.Append("<td colspan=\"3\"  ><p align=\"left\">QUÂN CHỦNG PK-KQ<BR/><span style=\"font-weight:bold;text-decoration:underline;padding-left:18px\">CÔNG TY ADCC</span><br/><span style=\"padding-left:16px\">BIỂU MẪU: 03/QS*2004</span></p></td>");
            sb.Append("<td colspan=\"32\" style=\"text-align:center;font-size:16px;font-weight:bold;\">DIỄN GIẢI CẤP BẬC QUÂN HÀM<br />"+DateTime.Now.Month+"/"+DateTime.Now.Year+"</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append(" <td rowspan=\"3\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333;width:200px;text-align:center\"><p>ĐƠN VỊ</p></td>");
            sb.Append(" <td rowspan=\"3\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333;width:35px;text-align:center\"><p>TỔNG<br/>SỐ</p></td>");
            sb.Append("<td colspan=\"13\" style=\"padding-left: 5px; border-left: 1px dotted #333; border-top: 1px dotted #333; text-align: center; font-weight: bold; text-transform: uppercase;\"> CƠ QUAN CÁN BỘ QUẢN LÝ</td>");
            sb.Append("<td colspan=\"11\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center; font-weight: bold; text-transform: uppercase;\">CƠ QUAN QUÂN LỰC QUẢN LÝ</td>");
            sb.Append("<td colspan=\"2\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-right:1px dotted #333;border-top:1px dotted #333;text-align:center;\">HĐLĐ</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"35\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;;width:35px;text-align:center\">TỔNG SỐ</td>");
            sb.Append("<td colspan=\"9\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center;  text-transform: uppercase;\">SỸ QUAN</td>");
            sb.Append("<td colspan=\"3\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align:center\"> DIỆN KHÁC</td>");
            sb.Append("<td width=\"35\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;;width:35px;text-align:center\">TỔNG SỐ</td>");
            sb.Append("<td colspan=\"9\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align:center;;width:35px;\">QNCN</td>");
            sb.Append("<td  rowspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333;width:35px;text-align:center\"><p>CNV<br />QP</p></td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;;border-top:1px dotted #333;border-bottom:1px dotted #333;width:35px;\">*</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:35px;\">4//</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:35px;\">3//</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:35px;\">2//</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:35px;\">1//</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:35px;\">4/</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:35px;\">3/</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:35px;\">2/</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:35px;\">1/</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:35px;\">*</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:35px;\">QN<br />CN</td>");
            sb.Append("<td  style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:35px;\">CC<br />QP</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:35px;\">*</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:35px;\">4//</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:35px;\">3//</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:35px;\">2//</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:35px;\">1//</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:35px;\">4/</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:35px;\">3/</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:35px;\">2/</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:35px;\">1/</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:35px;\">DH</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-right:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:35px;\">NH</td>");
            sb.Append("</tr>");
            foreach (var item in page_list_department)
            {
                var total_all = 0;
                var total_1 = 0;
                var total_2 = 0;

                var re3 = (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 3) != null ? profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 3).employee_no : 0) ?? 0;
                var re4 = (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 4) != null ? profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 4).employee_no : 0) ?? 0;
                var re5 = (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 5) != null ? profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 5).employee_no : 0) ?? 0;
                var re6 = (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 6) != null ? profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 6).employee_no : 0) ?? 0;
                var re7 = (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 7) != null ? profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 7).employee_no : 0) ?? 0;
                var re11 = (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 11) != null ? profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 11).employee_no : 0) ?? 0;
                var re10 = (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 10) != null ? profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 10).employee_no : 0) ?? 0;
                var re9 = (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 9) != null ? profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 9).employee_no : 0) ?? 0;
                var re8 = (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 8) != null ? profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 8).employee_no : 0) ?? 0;
                var re13 = (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 13) != null ? profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 13).employee_no : 0) ?? 0;
                var re14 = (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 14) != null ? profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 14).employee_no : 0) ?? 0;
                var re15 = (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 15) != null ? profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 15).employee_no : 0) ?? 0;

                total_1 = re3 + re4 + re5 + re6 + re7 + re8 + re9 + re10 + re11 + re13 + re14 + re15;

                var re18 = (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 18) != null ? profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 18).employee_no : 0) ?? 0;
                var re19 = (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 19) != null ? profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 19).employee_no : 0) ?? 0;
                var re20 = (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 20) != null ? profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 20).employee_no : 0) ?? 0;
                var re21 = (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 21) != null ? profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 21).employee_no : 0) ?? 0;
                var re22 = (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 22) != null ? profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 22).employee_no : 0) ?? 0;
                var re26 = (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 26) != null ? profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 26).employee_no : 0) ?? 0;
                var re25 = (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 25) != null ? profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 25).employee_no : 0) ?? 0;
                var re24 = (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 24) != null ? profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 24).employee_no : 0) ?? 0;
                var re23 = (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 23) != null ? profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 23).employee_no : 0) ?? 0;
                var re27 = (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 27) != null ? profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 27).employee_no : 0) ?? 0;

                total_2 = re18 + re19 + re20 + re21 + re22 + re23 + re24 + re25 + re26 + re27;

                var re_dh = profileModels.getNoHDDHBydepartmentID(item.departments_id);
                var re_nh = profileModels.getNoHDNHBydepartmentID(item.departments_id);

                total_all = total_1 + total_2 + re_dh + re_nh;

            sb.Append("<tr>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\"><strong>" + item.departments_name + "</strong></td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;"+total_all+"</td>");//Thêm cột tổng số mới
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;"+total_1+"</td>");//Thêm cột tổng số mới

            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 3) != null ? profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 3).employee_no.ToString() : "0").ToString() + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 4) != null ? (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 4).employee_no??0).ToString() : "0").ToString() + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 5) != null ? (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 5).employee_no??0).ToString() : "0").ToString() + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 6) != null ? (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 6).employee_no??0).ToString() : "0").ToString() + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 7) != null ? (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 7).employee_no??0).ToString() : "0").ToString() + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 11) != null ? (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 11).employee_no??0).ToString() : "0").ToString() + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 10) != null ? (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 10).employee_no??0).ToString() : "0").ToString() + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 9) != null ? (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 9).employee_no??0).ToString() : "0").ToString() + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 8) != null ? (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 8).employee_no??0).ToString() : "0").ToString() + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 13) != null ? (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 13).employee_no??0).ToString() : "0").ToString() + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 14) != null ? (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 14).employee_no??0).ToString() : "0").ToString() + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 15) != null ? (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 15).employee_no ?? 0).ToString() : "0").ToString() + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;"+total_2+"</td>");     //Tổng số chưa làm
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 18) != null ? (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 18).employee_no??0).ToString() : "0").ToString() + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 19) != null ? (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 19).employee_no??0).ToString() : "0").ToString() + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 20) != null ? (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 20).employee_no??0).ToString() : "0").ToString() + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 21) != null ? (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 21).employee_no??0).ToString() : "0").ToString() + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 22) != null ? (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 22).employee_no??0).ToString() : "0").ToString() + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 26) != null ? (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 26).employee_no??0).ToString() : "0").ToString() + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 25) != null ? (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 25).employee_no??0).ToString() : "0").ToString() + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 24) != null ? (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 24).employee_no??0).ToString() : "0").ToString() + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 23) != null ? (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 23).employee_no??0).ToString() : "0").ToString() + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 27) != null ? (profileModels.getEmployee_ranks_objectByDepartmentIDandObject(item.departments_id, 27).employee_no ?? 0).ToString() : "0").ToString() + "</td>");
            //sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + profileModels.getNoHDDHBydepartmentID(item.departments_id) + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333\">&nbsp;" + profileModels.getNoHDNHBydepartmentID(item.departments_id) + "</td>"); 
            sb.Append("</tr>");
            }
          
            //sb.Append("<tr><td colspan=\"9\" style=\"text-transform:uppercase;padding-top:20px;padding-left:20px;text-align:left;\">Nhân viên thống kê</td></tr>");
            //sb.Append("<tr><td colspan=\"9\" style=\"text-transform:uppercase;padding-top:-20px;position: relative;text-align:right;padding-right:20px;\">Nhân viên chính trị</td></tr>");
            sb.Append("</table>");

            if (type == 3)
            {
                StringReader str = new StringReader(sb.ToString());
                HTMLWorker htmlworker = new HTMLWorker(document);
                htmlworker.Parse(str);
                Response.Flush();
                Response.Close();
                document.Close();
                Response.Write(document);
            }
            else
            {
                Response.Write(sb.ToString());
            }
            Response.End();

            return RedirectToAction("list_DG_CB_QH", new { id = 1, pagesize = pagesize, text_search = text_search, from_date = from_date, to_date = to_date });
        }

        //Danh sach Khen thuong CN
        public ActionResult list_KT_CN()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_list_KT_CN(DateTime? from_date, DateTime? to_date, int? id, string text_search, string arr_employee_id)
        {
            from_date = DateTime.Now.AddMonths(-6);
            to_date = DateTime.Now;
            return control_list_KT_CN(from_date, to_date, id ?? 1, 10, text_search, arr_employee_id);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_list_KT_CN(DateTime? from_date, DateTime? to_date, int? id, int? pagesize, string text_search, string arr_employee_id)
        {
            if (to_date > DateTime.Now)
            {
                to_date = DateTime.Now;
            }
            var KT_CN_view = new ViewModels.PageListKT_CNViewModels();
            TryUpdateModel(KT_CN_view);
            List<SelectListItem> sizeDrop = new List<SelectListItem>();
            sizeDrop.AddRange(new SelectListItem[] { 
                            new SelectListItem{Selected=pagesize==10?true:false, Text = "10", Value = "10" },
                            new SelectListItem{Selected=pagesize==25?true:false, Text = "25", Value = "25" },
                            new SelectListItem{Selected=pagesize==50?true:false, Text = "50", Value = "50" },
                            new SelectListItem{Selected=pagesize==100?true:false, Text = "100", Value = "100" }
                        });
            List<int> total_all = new List<int>();
            List<int> total_skill_reward_1 = new List<int>();
            List<int> total_skill_reward_2 = new List<int>();
            List<int> total_skill_reward_3 = new List<int>();
            id = id ?? 1;
            KT_CN_view.list_pagesize = sizeDrop;
            KT_CN_view.pagesize = pagesize ?? 10;
            KT_CN_view.id = id;
            KT_CN_view.page_list_individual = profileModels.getListEmployee_individual(id ?? 1, pagesize ?? 10, text_search, from_date, to_date, arr_employee_id, ref total_all, ref total_skill_reward_1, ref total_skill_reward_2, ref total_skill_reward_3);
            KT_CN_view.total_all = total_all;
            KT_CN_view.total_skill_reward_1 = total_skill_reward_1;
            KT_CN_view.total_skill_reward_2 = total_skill_reward_2;
            KT_CN_view.total_skill_reward_3 = total_skill_reward_3;
            KT_CN_view.from_date = from_date;
            KT_CN_view.to_date = to_date;
            KT_CN_view.text_search = text_search;
            KT_CN_view.arr_employee_id = arr_employee_id;
            return PartialView("../Shared/control_list_KT_CN", KT_CN_view);
        }

        public ActionResult list_KT_CN_export(int? type, DateTime? from_date, DateTime? to_date, int? id, int? pagesize, string text_search, string arr_employee_id)
        {
            if (to_date > DateTime.Now)
            {
                to_date = DateTime.Now;
            }
            List<int> total_all = new List<int>();
            List<int> total_skill_reward_1 = new List<int>();
            List<int> total_skill_reward_2 = new List<int>();
            List<int> total_skill_reward_3 = new List<int>();

            //khen thuong ca nhan
            Document document = new Document(PageSize.A4, 10, 40, 20, 40);
            var page_list_KT_CN = profileModels.getListEmployee_individual_export(text_search, from_date, to_date, arr_employee_id, ref total_all, ref total_skill_reward_1, ref total_skill_reward_2, ref total_skill_reward_3);
            Response.Clear();
            if (type == 1)
            {
                //export to excel
                Response.AddHeader("Content-Disposition", "attachment; filename=khen_thuong_ca_nhan_" + DateTime.Now.Year + ".xls");
                Response.ContentType = "application/ms-excel";
            }
            else if (type == 2)
            {
                //export to word
                Response.AddHeader("Content-Disposition", "attachment; filename=khen_thuong_ca_nhan_" + DateTime.Now.Year + ".doc");
                Response.ContentType = "application/ms-word";
            }
            else if (type == 3)
            {
                //export to pdf
                Response.AddHeader("content-disposition", "attachment; filename=khen_thuong_ca_nhan_" + DateTime.Now.Year + ".pdf");
                Response.ContentType = "application/octet-stream";
                PdfWriter.GetInstance(document, Response.OutputStream);
                document.Open();
            }

            Response.Charset = string.Empty;
            Response.ContentEncoding = Encoding.Unicode;
            Response.BinaryWrite(Encoding.Unicode.GetPreamble());
            StringBuilder sb = new StringBuilder();
            sb.Append("<style>");
            sb.Append("@page Section1 {size:595.45pt 841.7pt; margin:1.03cm 1.25cm 1.0cm 1.25cm;mso-header-margin:.5cm;mso-footer-margin:.5cm;mso-paper-source:0;}");
            sb.Append("div.Section1 {page:Section1;}");
            sb.Append("@page Section2 {size:841.7pt 595.45pt;mso-page-orientation:landscape;margin:1.03cm 1.0cm 1.25cm 1.0cm;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}");
            sb.Append("div.Section2 {page:Section2;}");
            sb.Append("</style>");
            sb.Append("</head>");
            sb.Append("<body>");
            sb.Append("<div class=Section2>");
            sb.Append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"padding:0px;margin:0px\" >");
            sb.Append("<tr>");
            //sb.Append("<td colspan=\"38\" style=\"text-align:center;font-size:16px;font-weight:bold;\">DANH SÁCH KHEN THƯỞNG ĐỐI VỚI CÁ NHÂN<br />Từ:"+(from_date.Value.Month+"/"+from_date.Value.Year +" Đến:"+ to_date.Value.Month +"/"+to_date.Value.Year) +"</td>");
            //sb.Append("<td colspan=\"38\" style=\"text-align:center;font-size:16px;font-weight:bold;\">DANH SÁCH KHEN THƯỞNG ĐỐI VỚI CÁ NHÂN<br />Từ: 2004-2006</td>");
            sb.Append("<td colspan=\"38\" style=\"text-align:center;font-size:16px;font-weight:bold;\">DANH SÁCH KHEN THƯỞNG ĐỐI VỚI CÁ NHÂN<br />Từ:" + (from_date.Value.Day+"/"+ from_date.Value.Month + "/" + from_date.Value.Year + " Đến:" + to_date.Value.Day + "/" + to_date.Value.Month + "/" + to_date.Value.Year) + "</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td rowspan=\"3\" style=\"padding-left:5px;padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333\">STT</td>");
            sb.Append("<td  rowspan=\"3\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333;width:1000px\">HỌ VÀ TÊN</td>");
            sb.Append("<td  rowspan=\"3\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333;width:250px\">CẤP BẬC<BR/>CHỨC VỤ</td>");
            sb.Append("<td colspan=\"13\" style=\"padding-left: 5px; border-left: 1px dotted #333; border-top: 1px dotted #333; text-align: center;  text-transform: uppercase;\">CÁC HÌNH THỨC KHEN THƯỞNG</td>");
            sb.Append("<td rowspan=\"3\" style=\"padding-left: 5px; border-left: 1px dotted #333; border-top: 1px dotted #333; text-align: center;  text-transform: uppercase;border-bottom: 1px dotted #333;width:150px;\">SỐ,QĐ<br />NGÀY KÝ</td>");
            sb.Append("<td width=\"\" rowspan=\"3\" style=\"padding-left: 5px; border-left: 1px dotted #333; border-top: 1px dotted #333; text-align: center; text-transform: uppercase;border-right:1px dotted #333;border-bottom: 1px dotted #333;width:150px;\">LÝ DO KHEN</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"312\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center;  border-bottom:1px dotted #333\">Nhà nước</td>");
            sb.Append("<td width=\"312\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center; border-bottom:1px dotted #333\">Chính phủ</td>");
            sb.Append("<td width=\"312\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center;  text-transform: uppercase;border-bottom:1px dotted #333\">BQP</td>");
            sb.Append("<td width=\"312\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center; border-bottom:1px dotted #333\">Khác</td>");
            sb.Append("<td colspan=\"5\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center;  text-transform: uppercase;\">QUÂN CHỦNG</td>");
            sb.Append("<td colspan=\"4\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center;  text-transform: uppercase;\">CÔNG TY</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">CSTĐ</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">BK</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">GK</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">CSTT<br/>LĐTT</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">Khen khác</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">BK</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">GK</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">CSTT<br />LĐTT</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">Khen khác</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td colspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">Tổng:</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;</td>");
            //for (int i = 0; i < total_all.Count; i++)
            //{
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[i] + "</td>");
            //}
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[0] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[1] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[2] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[3] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[4] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[5] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[6] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[7] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[8] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[10] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[11] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[12] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[13] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[15] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;boder-right:1px dotted #333;\">&nbsp;</td>");
            sb.Append("</tr>");
            var list_skill_reward1=page_list_KT_CN.Where(p=>p.skill_reward==1).ToList();
            var list_skill_reward2=page_list_KT_CN.Where(p=>p.skill_reward==2).ToList();
            var list_skill_reward3=page_list_KT_CN.Where(p=>p.skill_reward==3).ToList();

            sb.Append("<tr>");
            sb.Append("<td colspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">PHẦN I: CHÍNH QUYỀN</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;</td>");
            //for (int i = 0; i < total_skill_reward_1.Count; i++)
            //{
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[i] + "</td>");
            //}
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[0] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[1] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[2] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[3] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[4] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[5] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[6] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[7] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[8] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[11] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[12] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[13] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[15] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;</td>");
            sb.Append("</tr>");

            for (int i=0;i< list_skill_reward1.Count();i++) //chinh quyen
            {
                var no_reward = list_skill_reward1[i].form_reward;
                sb.Append("<tr>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">"+(i+1)+"</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;"+list_skill_reward1[i].full_name+"</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;- " + list_skill_reward1[i].ranks + "<br/>- " + list_skill_reward1[i].positions + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "1" ? "x" : "&nbsp;")+"</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "2" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "3" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "4" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "5" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "6" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "7" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "8" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "9" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "12" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "13" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "14" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "16" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + list_skill_reward1[i].reward_number + "<br/>" + String.Format("{0:dd/MM/yyyy}", list_skill_reward1[i].signature_date) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;" + list_skill_reward1[i].descriptions + "</td>");
                sb.Append("</tr>");
            }

            sb.Append("<tr>");
            sb.Append("<td colspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">PHẦN II: TỔ CHỨC ĐẲNG</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;</td>");
            //for (int i = 0; i < total_skill_reward_2.Count; i++)
            //{
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[i] + "</td>");
            //}
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[0] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[1] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[2] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[3] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[4] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[5] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[6] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[7] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[8] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[11] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[12] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[13] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[15] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;</td>");
            sb.Append("</tr>");

            for (int i = 0; i < list_skill_reward2.Count(); i++)    //to chuc dang
            {
                var no_reward = list_skill_reward2[i].form_reward;
                sb.Append("<tr>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">" + (i + 1) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + list_skill_reward2[i].full_name + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;- " + list_skill_reward2[i].ranks + "<br/>- " + list_skill_reward2[i].positions + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "1" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "2" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "3" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "4" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "5" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "6" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "7" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "8" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "9" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "12" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "13" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "14" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "16" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + list_skill_reward2[i].reward_number + "<br/>" + String.Format("{0:dd/MM/yyyy}", list_skill_reward2[i].signature_date) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;" + list_skill_reward2[i].descriptions + "</td>");
                sb.Append("</tr>");
            }

            sb.Append("<tr>");
            sb.Append("<td colspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">PHẦN III: TỔ CHỨC QUẦN CHÚNG</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;</td>");
            //for (int i = 0; i < total_skill_reward_3.Count; i++)
            //{
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[i] + "</td>");
            //}
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[0] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[1] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[2] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[3] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[4] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[5] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[6] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[7] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[8] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[11] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[12] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[13] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[15] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;</td>");
            sb.Append("</tr>");

            for (int i = 0; i < list_skill_reward3.Count(); i++)    //to chuc quan chung
            {
                var no_reward = list_skill_reward3[i].form_reward;
                sb.Append("<tr>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">" + (i + 1) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + list_skill_reward3[i].full_name + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;- " + list_skill_reward3[i].ranks + "<br/>- " + list_skill_reward3[i].positions + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "1" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "2" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "3" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "4" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "5" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "6" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "7" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "8" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "9" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "12" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "13" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "14" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "16" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + list_skill_reward3[i].reward_number + "<br/>" + String.Format("{0:dd/MM/yyyy}", list_skill_reward3[i].signature_date) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;" + list_skill_reward3[i].descriptions + "</td>");
                sb.Append("</tr>");
            }

            
            
            
            //sb.Append("<tr><td colspan=\"9\" style=\"text-transform:uppercase;padding-top:20px;padding-left:20px;text-align:left;\">Nhân viên thống kê</td></tr>");
            //sb.Append("<tr><td colspan=\"9\" style=\"text-transform:uppercase;padding-top:-20px;position: relative;text-align:right;padding-right:20px;\">Nhân viên chính trị</td></tr>");
            sb.Append("</table>");
            sb.Append("</div>");

            if (type == 3)
            {
                StringReader str = new StringReader(sb.ToString());
                HTMLWorker htmlworker = new HTMLWorker(document);
                htmlworker.Parse(str);
                Response.Flush();
                Response.Close();
                document.Close();
                Response.Write(document);
            }
            else
            {
                Response.Write(sb.ToString());
            }
            Response.End();

            return RedirectToAction("list_KT_CN", new { id = 1, pagesize = pagesize, text_search = text_search, from_date = from_date, to_date = to_date });
        }

        //Danh sach Tổng kết Khen thuong CN (Tổng kết)
        public ActionResult list_KT_CN_total()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_list_KT_CN_total(DateTime? from_date, DateTime? to_date, int? id, string text_search, string arr_employee_id)
        {
            from_date = DateTime.Now.AddMonths(-6);
            to_date = DateTime.Now;
            var KT_CN__total_view = new ViewModels.PageListKT_CN_totalViewModels();
            KT_CN__total_view.list_employees = h_contentModels.getListEmployeesBirthday();
            KT_CN__total_view.arr_employee_id = arr_employee_id;
            return control_list_KT_CN_total(from_date, to_date, id ?? 1, 10, text_search, arr_employee_id);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_list_KT_CN_total(DateTime? from_date, DateTime? to_date, int? id, int? pagesize, string text_search, string arr_employee_id)
        {
            if (to_date > DateTime.Now)
            {
                to_date = DateTime.Now;
            }
            var KT_CN__total_view = new ViewModels.PageListKT_CN_totalViewModels();
            TryUpdateModel(KT_CN__total_view);
            KT_CN__total_view.list_employees = h_contentModels.getListEmployeesBirthday();
            List<SelectListItem> sizeDrop = new List<SelectListItem>();
            sizeDrop.AddRange(new SelectListItem[] { 
                            new SelectListItem{Selected=pagesize==10?true:false, Text = "10", Value = "10" },
                            new SelectListItem{Selected=pagesize==25?true:false, Text = "25", Value = "25" },
                            new SelectListItem{Selected=pagesize==50?true:false, Text = "50", Value = "50" },
                            new SelectListItem{Selected=pagesize==100?true:false, Text = "100", Value = "100" }
                        });
            List<int> total_all = new List<int>();
            List<int> total_skill_reward_1 = new List<int>();
            List<int> total_skill_reward_2 = new List<int>();
            List<int> total_skill_reward_3 = new List<int>();
            id = id ?? 1;
            KT_CN__total_view.list_pagesize = sizeDrop;
            KT_CN__total_view.pagesize = pagesize ?? 10;
            KT_CN__total_view.id = id;
            KT_CN__total_view.page_list_individual = profileModels.getListEmployee_individual_total(id ?? 1, pagesize ?? 10, text_search, from_date, to_date, arr_employee_id, ref total_all, ref total_skill_reward_1, ref total_skill_reward_2, ref total_skill_reward_3);
            KT_CN__total_view.total_all = total_all;
            KT_CN__total_view.total_skill_reward_1 = total_skill_reward_1;
            KT_CN__total_view.total_skill_reward_2 = total_skill_reward_2;
            KT_CN__total_view.total_skill_reward_3 = total_skill_reward_3;
            KT_CN__total_view.from_date = from_date;
            KT_CN__total_view.to_date = to_date;
            KT_CN__total_view.text_search = text_search;
            KT_CN__total_view.arr_employee_id = arr_employee_id;
            return PartialView("../Shared/control_list_KT_CN_total", KT_CN__total_view);
        }

        public ActionResult list_KT_CN_total_export(int? type, DateTime? from_date, DateTime? to_date, int? id, int? pagesize, string text_search, string arr_employee_id)
        {
            if (to_date > DateTime.Now)
            {
                to_date = DateTime.Now;
            }
            List<int> total_all = new List<int>();
            List<int> total_skill_reward_1 = new List<int>();
            List<int> total_skill_reward_2 = new List<int>();
            List<int> total_skill_reward_3 = new List<int>();

            //khen thuong ca nhan
            Document document = new Document(PageSize.A4.Rotate(),10,10,10,10);
            var page_list_KT_CN_total = profileModels.getListEmployee_individual_export_total(text_search, from_date, to_date, arr_employee_id, ref total_all, ref total_skill_reward_1, ref total_skill_reward_2, ref total_skill_reward_3);
            Response.Clear();
            if (type == 1)
            {
                //export to excel
                Response.AddHeader("Content-Disposition", "attachment; filename=bao_cao_tong_khen_thuong_ca_nhan_" + DateTime.Now.Year + ".xls");
                Response.ContentType = "application/ms-excel";
            }
            else if (type == 2)
            {
                //export to word
                Response.AddHeader("Content-Disposition", "attachment; filename=bao_cao_tong_khen_thuong_ca_nhan_" + DateTime.Now.Year + ".doc");
                Response.ContentType = "application/ms-word";
            }
            else if (type == 3)
            {
                //export to pdf
                Response.AddHeader("content-disposition", "attachment; filename=bao_cao_tong_khen_thuong_ca_nhan_" + DateTime.Now.Year + ".pdf");
                Response.ContentType = "application/octet-stream";
                PdfWriter.GetInstance(document, Response.OutputStream);
                document.Open();
            }

            Response.Charset = string.Empty;
            Response.ContentEncoding = Encoding.Unicode;
            Response.BinaryWrite(Encoding.Unicode.GetPreamble());
            StringBuilder sb = new StringBuilder();
            sb.Append("<style>");
            sb.Append("@page Section1 {size:595.45pt 841.7pt; margin:1.03cm 1.25cm 1.0cm 1.25cm;mso-header-margin:.5cm;mso-footer-margin:.5cm;mso-paper-source:0;}");
            sb.Append("div.Section1 {page:Section1;}");
            sb.Append("@page Section2 {size:841.7pt 595.45pt;mso-page-orientation:landscape;margin:1.03cm 1.0cm 1.25cm 1.0cm;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}");
            sb.Append("div.Section2 {page:Section2;}");
            sb.Append("</style>");
            sb.Append("</head>");
            sb.Append("<body>");
            sb.Append("<div class=Section2>");
            sb.Append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"padding:0px;margin:0px;width:27.7cm\" >");
            sb.Append("<tr>");
            //sb.Append("<td colspan=\"38\" style=\"text-align:center;font-size:16px;font-weight:bold;\">DANH SÁCH TỔNG KẾT KHEN THƯỞNG ĐỐI VỚI CÁ NHÂN<br />Từ: 2004-2006</td>");
            sb.Append("<td colspan=\"38\" style=\"text-align:center;font-size:16px;font-weight:bold;\">DANH SÁCH TỔNG KẾT KHEN THƯỞNG ĐỐI VỚI CÁ NHÂN<br />Từ:" + (from_date.Value.Day + "/" + from_date.Value.Month + "/" + from_date.Value.Year + " Đến:" + to_date.Value.Day + "/" + to_date.Value.Month + "/" + to_date.Value.Year) + "</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td rowspan=\"3\" style=\"padding-left:5px;padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333\">STT</td>");
            sb.Append("<td  rowspan=\"3\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333;width:1000px\">HỌ VÀ TÊN</td>");
            sb.Append("<td  rowspan=\"3\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333;width:250px\">CẤP BẬC<BR/>CHỨC VỤ</td>");
            sb.Append("<td colspan=\"13\" style=\"padding-left: 5px; border-left: 1px dotted #333; border-top: 1px dotted #333; text-align: center;  text-transform: uppercase;\">CÁC HÌNH THỨC KHEN THƯỞNG</td>");
            sb.Append("<td width=\"\" rowspan=\"3\" style=\"padding-left: 5px; border-left: 1px dotted #333; border-top: 1px dotted #333; text-align: center; text-transform: uppercase;border-right:1px dotted #333;border-bottom: 1px dotted #333;width:150px;\">TỔNG</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"312\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center;  border-bottom:1px dotted #333\">Nhà nước</td>");
            sb.Append("<td width=\"312\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center; border-bottom:1px dotted #333\">Chính phủ</td>");
            sb.Append("<td width=\"312\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center;  text-transform: uppercase;border-bottom:1px dotted #333\">BQP</td>");
            sb.Append("<td width=\"312\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center; border-bottom:1px dotted #333\">Khác</td>");
            sb.Append("<td colspan=\"5\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center;  text-transform: uppercase;\">QUÂN CHỦNG</td>");
            sb.Append("<td colspan=\"4\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center;  text-transform: uppercase;\">CÔNG TY</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">CSTĐ</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">BK</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">GK</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">CSTT<br/>LĐTT</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">Khen khác</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">BK</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">GK</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">CSTT<br />LĐTT</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">Khen khác</td>");
            sb.Append("</tr>");

            sb.Append("<tr>");
            sb.Append("<td colspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">Tổng:</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;</td>");
            var all_total = 0;
            for (int i = 0; i < total_all.Count; i++)
            {

                all_total = all_total + (int)total_all[i];



            }
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[0] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[1] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[2] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[3] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[4] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[5] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[6] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[7] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[8] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[11] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[12] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[13] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[15] + "</td>");
            if(all_total==0){
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
            }
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;"+all_total+"</td>");
            sb.Append("</tr>");
            //var list_skill_reward1 = page_list_KT_CN_total.Where(p => p.skill_reward == 1).ToList();
            //var list_skill_reward2 = page_list_KT_CN_total.Where(p => p.skill_reward == 2).ToList();
            //var list_skill_reward3 = page_list_KT_CN_total.Where(p => p.skill_reward == 3).ToList();

            for (int i = 0; i < page_list_KT_CN_total.Count(); i++) //chinh quyen
            {
                var em_i = profileModels.getEmployeeByID(page_list_KT_CN_total[i].employee_id);
                sb.Append("<tr>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">" + (i + 1) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + page_list_KT_CN_total[i].full_name + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;- " + ((em_i != null ? em_i.ranks : "&nbsp;") + "<br/>- " + (em_i != null ? em_i.positions : "&nbsp;")) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_CN_total[i].total_reward_1) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_CN_total[i].total_reward_2) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_CN_total[i].total_reward_3) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_CN_total[i].total_reward_4) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_CN_total[i].total_reward_5) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_CN_total[i].total_reward_6) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_CN_total[i].total_reward_7) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_CN_total[i].total_reward_8) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_CN_total[i].total_reward_9) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_CN_total[i].total_reward_12) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_CN_total[i].total_reward_13) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_CN_total[i].total_reward_14) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_CN_total[i].total_reward_16) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp; " + (page_list_KT_CN_total[i].total_reward) + " </td>");//Tính tổng vào đây
                sb.Append("</tr>");
            }

            //sb.Append("<tr>");
            //sb.Append("<td colspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">PHẦN I: CHÍNH QUYỀN</td>");
            //sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;</td>");
            //for (int i = 0; i < total_skill_reward_1.Count; i++)
            //{
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[i] + "</td>");
            //}
            
            //sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;</td>");
            //sb.Append("</tr>");

            //for (int i = 0; i < list_skill_reward1.Count(); i++) //chinh quyen
            //{
            //    var em_i = profileModels.getEmployeeByID(list_skill_reward1[i].employee_id);
            //    sb.Append("<tr>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">" + (i + 1) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + list_skill_reward1[i].full_name + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;- " + ((em_i != null ? em_i.ranks : "&nbsp;") + "<br/>- " + (em_i != null ? em_i.positions : "&nbsp;")) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward1[i].total_reward_1) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward1[i].total_reward_2) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward1[i].total_reward_3) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward1[i].total_reward_4) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward1[i].total_reward_5) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward1[i].total_reward_6) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward1[i].total_reward_7) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward1[i].total_reward_8) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward1[i].total_reward_9) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward1[i].total_reward_10) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward1[i].total_reward_11) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward1[i].total_reward_12) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward1[i].total_reward_13) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp; " + (list_skill_reward1[i].total_reward_skill) + " </td>");//Tính tổng vào đây
            //    sb.Append("</tr>");
            //}

            //sb.Append("<tr>");
            //sb.Append("<td colspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">PHẦN II: TỔ CHỨC ĐẲNG</td>");
            //sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;</td>");
            //for (int i = 0; i < total_skill_reward_2.Count; i++)
            //{
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[i] + "</td>");
            //}
           
            //sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;</td>");
            //sb.Append("</tr>");

            //for (int i = 0; i < list_skill_reward2.Count(); i++)    //to chuc dang
            //{
            //    var em_i = profileModels.getEmployeeByID(list_skill_reward2[i].employee_id);
            //    sb.Append("<tr>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">" + (i + 1) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + list_skill_reward2[i].full_name + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;- " + ((em_i != null ? em_i.ranks : "&nbsp;") + "<br/>- " + (em_i != null ? em_i.positions : "&nbsp;")) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward2[i].total_reward_1) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward2[i].total_reward_2) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward2[i].total_reward_3) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward2[i].total_reward_4) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward2[i].total_reward_5) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward2[i].total_reward_6) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward2[i].total_reward_7) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward2[i].total_reward_8) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward2[i].total_reward_9) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward2[i].total_reward_10) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward2[i].total_reward_11) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward2[i].total_reward_12) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward2[i].total_reward_13) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp; " + (list_skill_reward2[i].total_reward_skill) + " </td>");//Tính tổng vào đây
            //    sb.Append("</tr>");
            //}

            //sb.Append("<tr>");
            //sb.Append("<td colspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">PHẦN III: TỔ CHỨC QUẦN CHÚNG</td>");
            //sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;</td>");
            //for (int i = 0; i < total_skill_reward_3.Count; i++)
            //{
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[i] + "</td>");
            //}
            //sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;</td>");
            //sb.Append("</tr>");

            //for (int i = 0; i < list_skill_reward3.Count(); i++)    //to chuc quan chung
            //{
            //    var em_i = profileModels.getEmployeeByID(list_skill_reward3[i].employee_id);
            //    sb.Append("<tr>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">" + (i + 1) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + list_skill_reward3[i].full_name + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;- " + ((em_i != null ? em_i.ranks : "&nbsp;") + "<br/>- " + (em_i != null ? em_i.positions : "&nbsp;")) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward3[i].total_reward_1) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward3[i].total_reward_2) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward3[i].total_reward_3) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward3[i].total_reward_4) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward3[i].total_reward_5) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward3[i].total_reward_6) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward3[i].total_reward_7) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward3[i].total_reward_8) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward3[i].total_reward_9) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward3[i].total_reward_10) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward3[i].total_reward_11) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward3[i].total_reward_12) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (list_skill_reward3[i].total_reward_13) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp; " + (list_skill_reward3[i].total_reward_skill) + " </td>");//Tính tổng vào đây
            //    sb.Append("</tr>");
            //}

            


            //sb.Append("<tr><td colspan=\"9\" style=\"text-transform:uppercase;padding-top:20px;padding-left:20px;text-align:left;\">Nhân viên thống kê</td></tr>");
            //sb.Append("<tr><td colspan=\"9\" style=\"text-transform:uppercase;padding-top:-20px;position: relative;text-align:right;padding-right:20px;\">Nhân viên chính trị</td></tr>");
            sb.Append("</table>");
            sb.Append("</div>");

            if (type == 3)
            {
                StringReader str = new StringReader(sb.ToString());
                HTMLWorker htmlworker = new HTMLWorker(document);
                htmlworker.Parse(str);
                Response.Flush();
                Response.Close();
                document.Close();
                Response.Write(document);
            }
            else
            {
                Response.Write(sb.ToString());
            }
            Response.End();

            return RedirectToAction("list_KT_CN_total", new { id = 1, pagesize = pagesize, text_search = text_search, from_date = from_date, to_date = to_date });
        }
        //Báo cáo khen thưởng tập thể total
        public ActionResult list_KT_TT_total()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_list_KT_TT_total(DateTime? from_date, DateTime? to_date, int? id, string text_search, string arr_departments_id)
        {
            from_date = DateTime.Now.AddMonths(-6);
            to_date = DateTime.Now;
            var KT_TT_total_view = new ViewModels.PageListKT_TT_totalViewModels();
            KT_TT_total_view.list_department = h_contentModels.getListDepartmentsBuilder(null);
            KT_TT_total_view.arr_departments_id = arr_departments_id;
            return control_list_KT_TT_total(from_date, to_date, id ?? 1, 10, text_search, arr_departments_id);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_list_KT_TT_total(DateTime? from_date, DateTime? to_date, int? id, int? pagesize, string text_search, string arr_departments_id)
        {
            if (to_date > DateTime.Now)
            {
                to_date = DateTime.Now;
            }
            var KT_TT_total_view = new ViewModels.PageListKT_TT_totalViewModels();
            TryUpdateModel(KT_TT_total_view);
            KT_TT_total_view.list_department = h_contentModels.getListDepartmentsBuilder(null);
            List<SelectListItem> sizeDrop = new List<SelectListItem>();
            sizeDrop.AddRange(new SelectListItem[] { 
                            new SelectListItem{Selected=pagesize==10?true:false, Text = "10", Value = "10" },
                            new SelectListItem{Selected=pagesize==25?true:false, Text = "25", Value = "25" },
                            new SelectListItem{Selected=pagesize==50?true:false, Text = "50", Value = "50" },
                            new SelectListItem{Selected=pagesize==100?true:false, Text = "100", Value = "100" }
                        });
            List<int> total_all = new List<int>();
            List<int> total_skill_reward_1 = new List<int>();
            List<int> total_skill_reward_2 = new List<int>();
            List<int> total_skill_reward_3 = new List<int>();
            id = id ?? 1;
            pagesize = pagesize ?? 10;
            KT_TT_total_view.list_pagesize = sizeDrop;
            KT_TT_total_view.pagesize = pagesize ?? 10;
            KT_TT_total_view.id = id;
            KT_TT_total_view.page_list_collective = profileModels.getListEmployee_collective_total(id ?? 1, pagesize ?? 10, text_search, from_date, to_date, arr_departments_id, ref total_all, ref total_skill_reward_1, ref total_skill_reward_2, ref total_skill_reward_3);
            KT_TT_total_view.total_all = total_all;
            KT_TT_total_view.total_skill_reward_1 = total_skill_reward_1;
            KT_TT_total_view.total_skill_reward_2 = total_skill_reward_2;
            KT_TT_total_view.total_skill_reward_3 = total_skill_reward_3;
            KT_TT_total_view.from_date = from_date;
            KT_TT_total_view.to_date = to_date;
            KT_TT_total_view.text_search = text_search;
            KT_TT_total_view.arr_departments_id = arr_departments_id;
            return PartialView("../Shared/control_list_KT_TT_total", KT_TT_total_view);
        }

        public ActionResult list_KT_TT_total_export(int? type, DateTime? from_date, DateTime? to_date, int? id, int? pagesize, string text_search, string arr_departments_id)
        {
            if (to_date > DateTime.Now)
            {
                to_date = DateTime.Now;
            }
            List<int> total_all = new List<int>();
            List<int> total_skill_reward_1 = new List<int>();
            List<int> total_skill_reward_2 = new List<int>();
            List<int> total_skill_reward_3 = new List<int>();

            //khen thuong tập thể
            Document document = new Document(PageSize.A4, 10, 10, 15, 15);
            var page_list_KT_TT_total = profileModels.getListEmployee_collective_export_total(text_search, from_date, to_date, arr_departments_id, ref total_all, ref total_skill_reward_1, ref total_skill_reward_2, ref total_skill_reward_3);
            Response.Clear();
            if (type == 1)
            {
                //export to excel
                Response.AddHeader("Content-Disposition", "attachment; filename=Bao_cao_khen_thuong_tap_the_tong" + DateTime.Now.Year + ".xls");
                Response.ContentType = "application/ms-excel";
            }
            else if (type == 2)
            {
                //export to word
                Response.AddHeader("Content-Disposition", "attachment; filename=Bao_cao_khen_thuong_tap_the_tong" + DateTime.Now.Year + ".doc");
                Response.ContentType = "application/ms-word";
            }
            else if (type == 3)
            {
                //export to pdf
                Response.AddHeader("content-disposition", "attachment; filename=Bao_cao_khen_thuong_tap_the_tong" + DateTime.Now.Year + ".pdf");
                Response.ContentType = "application/octet-stream";
                PdfWriter.GetInstance(document, Response.OutputStream);
                document.Open();
            }

            Response.Charset = string.Empty;
            Response.ContentEncoding = Encoding.Unicode;
            Response.BinaryWrite(Encoding.Unicode.GetPreamble());
            StringBuilder sb = new StringBuilder();
            sb.Append("<style>");
            sb.Append("@page Section1 {size:595.45pt 841.7pt; margin:1.03cm 1.25cm 1.0cm 1.25cm;mso-header-margin:.5cm;mso-footer-margin:.5cm;mso-paper-source:0;}");
            sb.Append("div.Section1 {page:Section1;}");
            sb.Append("@page Section2 {size:841.7pt 595.45pt;mso-page-orientation:landscape;margin:1.03cm 1.0cm 1.25cm 1.0cm;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}");
            sb.Append("div.Section2 {page:Section2;}");
            sb.Append("</style>");
            sb.Append("</head>");
            sb.Append("<body>");
            sb.Append("<div class=Section2>");
       
            

            sb.Append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"padding:0px;margin:0px;width:27.7cm\" >");
            sb.Append("<tr>");
            sb.Append("<td colspan=\"38\" style=\"text-align:center;font-size:16px;font-weight:bold;\">DANH SÁCH TỔNG KẾT KHEN THƯỞNG ĐỐI VỚI TẬP THỂ<br />Từ:" + (from_date.Value.Day + "/" + from_date.Value.Month + "/" + from_date.Value.Year + " Đến:" + to_date.Value.Day + "/" + to_date.Value.Month + "/" + to_date.Value.Year) + "</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td rowspan=\"3\" style=\"padding-left:5px;padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333\">STT</td>");
            sb.Append("<td  rowspan=\"3\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333;width:1000px\">ĐƠN VỊ</td>");
            //sb.Append("<td  rowspan=\"3\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333;width:250px\">CẤP BẬC<BR/>CHỨC VỤ</td>");
            sb.Append("<td colspan=\"13\" style=\"padding-left: 5px; border-left: 1px dotted #333; border-top: 1px dotted #333; text-align: center;  text-transform: uppercase;\">CÁC HÌNH THỨC KHEN THƯỞNG</td>");
            sb.Append("<td width=\"\" rowspan=\"3\" style=\"padding-left: 5px; border-left: 1px dotted #333; border-top: 1px dotted #333; text-align: center; text-transform: uppercase;border-right:1px dotted #333;border-bottom: 1px dotted #333;width:150px;\">TỔNG");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"312\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center;  border-bottom:1px dotted #333\">Nhà nước</td>");
            sb.Append("<td width=\"312\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center; border-bottom:1px dotted #333\">Chính phủ</td>");
            sb.Append("<td width=\"312\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center;  text-transform: uppercase;border-bottom:1px dotted #333\">BQP</td>");
            sb.Append("<td width=\"312\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center; border-bottom:1px dotted #333\">Khác</td>");
            sb.Append("<td colspan=\"5\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center;  text-transform: uppercase;\">QUÂN CHỦNG</td>");
            sb.Append("<td colspan=\"4\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center;  text-transform: uppercase;\">CÔNG TY</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">ĐVQT</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">BK</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">GK</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">ĐVTT</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">Khen khác</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">BK</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">GK</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">ĐVTT</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">Khen khác</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td colspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">Tổng:</td>");
            var all_total = 0;
            for (int i = 0; i < total_all.Count; i++)
            {
                all_total = all_total + (int)total_all[i];
                
            }
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[0] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[1] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[2] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[3] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[9] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[5] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[6] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[10] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[8] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[11] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[12] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[14] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[15] + "</td>");
            if(all_total==0){
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;0</td>");
            }
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;"+all_total+"</td>");
            sb.Append("</tr>");

            for (int i = 0; i < page_list_KT_TT_total.Count(); i++) //chinh quyen
            {
                var dep = h_contentModels.getDepartmentsByID(page_list_KT_TT_total[i].departments_id??0);
                sb.Append("<tr>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">" + (i + 1) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + page_list_KT_TT_total[i].departments_name + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_TT_total[i].total_reward_1) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_TT_total[i].total_reward_2) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_TT_total[i].total_reward_3) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_TT_total[i].total_reward_4) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_TT_total[i].total_reward_10) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_TT_total[i].total_reward_6) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_TT_total[i].total_reward_7) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_TT_total[i].total_reward_11) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_TT_total[i].total_reward_9) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_TT_total[i].total_reward_12) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_TT_total[i].total_reward_13) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_TT_total[i].total_reward_15) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (page_list_KT_TT_total[i].total_reward_16) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;" + (page_list_KT_TT_total[i].total_reward) + "</td>");//Đưa con số tổng ra đây
                sb.Append("</tr>");
            }

            //var list_skill_reward1 = page_list_KT_TT_total.Where(p => p.skill_reward == 1).ToList();
            //var list_skill_reward2 = page_list_KT_TT_total.Where(p => p.skill_reward == 2).ToList();
            //var list_skill_reward3 = page_list_KT_TT_total.Where(p => p.skill_reward == 3).ToList();

            //sb.Append("<tr>");
            //sb.Append("<td colspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">PHẦN I: CHÍNH QUYỀN</td>");
            //for (int i = 0; i < total_skill_reward_1.Count; i++)
            //{
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[i] + "</td>");
            //}
            //sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;</td>");
            //sb.Append("</tr>");

            //for (int i = 0; i < list_skill_reward1.Count(); i++) //chinh quyen
            //{
            //    var no_reward = list_skill_reward1[i].form_reward;
            //    var der = "";
            //    if (list_skill_reward1[i].departments_id != null)
            //    {
            //        der = h_contentModels.getDepartmentsByID(list_skill_reward1[i].departments_id ?? 0).departments_name;
            //    }
            //    else
            //    {
            //        der = list_skill_reward1[i].reward_name_group;
            //    }
            //    sb.Append("<tr>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">" + (i + 1) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + der + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "1" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "2" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "3" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "4" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "10" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "6" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "7" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "11" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "9" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "12" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "13" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "15" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "16" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;TỔNG</td>");//Đưa con số tổng ra đây
            //    sb.Append("</tr>");
            //}

            //sb.Append("<tr>");
            //sb.Append("<td colspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">PHẦN II: TỔ CHỨC ĐẲNG</td>");
            //for (int i = 0; i < total_skill_reward_2.Count; i++)
            //{
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[i] + "</td>");
            //}
            //sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;</td>");
            //sb.Append("</tr>");

            //for (int i = 0; i < list_skill_reward2.Count(); i++)    //to chuc dang
            //{
            //    var no_reward = list_skill_reward2[i].form_reward;
            //    var der = "";
            //    if (list_skill_reward2[i].departments_id != null)
            //    {
            //        der = h_contentModels.getDepartmentsByID(list_skill_reward2[i].departments_id ?? 0).departments_name;
            //    }
            //    else
            //    {
            //        der = list_skill_reward2[i].reward_name_group;
            //    }
            //    sb.Append("<tr>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">" + (i + 1) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + der + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "1" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "2" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "3" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "4" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "10" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "6" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "7" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "11" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "9" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "12" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "13" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "15" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "16" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;TỔNG</td>");//Đưa con số tổng ra đây
            //    sb.Append("</tr>");
            //}

            //sb.Append("<tr>");
            //sb.Append("<td colspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">PHẦN III: TỔ CHỨC QUẦN CHÚNG</td>");
            //for (int i = 0; i < total_skill_reward_3.Count; i++)
            //{
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[i] + "</td>");
            //}
            //sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;</td>");
            //sb.Append("</tr>");

            //for (int i = 0; i < list_skill_reward3.Count(); i++)    //to chuc quan chung
            //{
            //    var no_reward = list_skill_reward3[i].form_reward;
            //    var der = "";
            //    if (list_skill_reward3[i].departments_id != null)
            //    {
            //        der = h_contentModels.getDepartmentsByID(list_skill_reward3[i].departments_id ?? 0).departments_name;
            //    }
            //    else
            //    {
            //        der = list_skill_reward3[i].reward_name_group;
            //    }
            //    sb.Append("<tr>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">" + (i + 1) + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + der + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "1" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "2" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "3" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "4" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "10" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "6" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "7" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "11" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "9" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "12" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "13" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "15" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "16" ? "x" : "&nbsp;") + "</td>");
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;TỔNG</td>");//Đưa con số tổng ra đây
            //    sb.Append("</tr>");
            //}

            
            //sb.Append("<tr><td colspan=\"9\" style=\"text-transform:uppercase;padding-top:20px;padding-left:20px;text-align:left;\">Nhân viên thống kê</td></tr>");
            //sb.Append("<tr><td colspan=\"9\" style=\"text-transform:uppercase;padding-top:-20px;position: relative;text-align:right;padding-right:20px;\">Nhân viên chính trị</td></tr>");
            sb.Append("</table>");
            sb.Append("</div>");
            if (type == 3)
            {
                StringReader str = new StringReader(sb.ToString());
                HTMLWorker htmlworker = new HTMLWorker(document);
                htmlworker.Parse(str);
                Response.Flush();
                Response.Close();
                document.Close();
                Response.Write(document);
            }
            else
            {
                Response.Write(sb.ToString());
            }
            Response.End();

            return RedirectToAction("list_KT_TT_total", new { id = 1, pagesize = pagesize, text_search = text_search, from_date = from_date, to_date = to_date });
        }

        //Danh sach Khen thuong TT
        public ActionResult list_KT_TT()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        [HttpGet]
        public ActionResult control_list_KT_TT(DateTime? from_date, DateTime? to_date, int? id, string text_search, string arr_departments_id)
        {
            from_date = DateTime.Now.AddMonths(-6);
            to_date = DateTime.Now;
            return control_list_KT_TT(from_date, to_date, id ?? 1, 10, text_search, arr_departments_id);
        }

        [ChildActionOnly]
        [HttpPost]
        public ActionResult control_list_KT_TT(DateTime? from_date, DateTime? to_date, int? id, int? pagesize, string text_search, string arr_departments_id)
        {
            if (to_date > DateTime.Now)
            {
                to_date = DateTime.Now;
            }
            var KT_TT_view = new ViewModels.PageListKT_TTViewModels();
            TryUpdateModel(KT_TT_view);
            List<SelectListItem> sizeDrop = new List<SelectListItem>();
            sizeDrop.AddRange(new SelectListItem[] { 
                            new SelectListItem{Selected=pagesize==10?true:false, Text = "10", Value = "10" },
                            new SelectListItem{Selected=pagesize==25?true:false, Text = "25", Value = "25" },
                            new SelectListItem{Selected=pagesize==50?true:false, Text = "50", Value = "50" },
                            new SelectListItem{Selected=pagesize==100?true:false, Text = "100", Value = "100" }
                        });
            List<int> total_all=new List<int>();
            List<int> total_skill_reward_1 = new List<int>();
            List<int> total_skill_reward_2 = new List<int>();
            List<int> total_skill_reward_3 = new List<int>();
            id = id ?? 1;
            pagesize = pagesize ?? 10;
            KT_TT_view.list_pagesize = sizeDrop;
            KT_TT_view.pagesize = pagesize ?? 10;
            KT_TT_view.id = id;
            KT_TT_view.page_list_collective = profileModels.getListEmployee_collective(id ?? 1, pagesize ?? 10, text_search, from_date, to_date, arr_departments_id, ref total_all, ref total_skill_reward_1, ref total_skill_reward_2, ref total_skill_reward_3);
            KT_TT_view.total_all=total_all;
            KT_TT_view.total_skill_reward_1=total_skill_reward_1;
            KT_TT_view.total_skill_reward_2=total_skill_reward_2;
            KT_TT_view.total_skill_reward_3 = total_skill_reward_3;
            KT_TT_view.from_date = from_date;
            KT_TT_view.to_date = to_date;
            KT_TT_view.text_search = text_search;
            KT_TT_view.arr_departments_id = arr_departments_id;
            return PartialView("../Shared/control_list_KT_TT", KT_TT_view);
        }

        public ActionResult list_KT_TT_export(int? type, DateTime? from_date, DateTime? to_date, int? id, int? pagesize, string text_search, string arr_departments_id)
        {
            if (to_date > DateTime.Now)
            {
                to_date = DateTime.Now;
            }
            List<int> total_all = new List<int>();
            List<int> total_skill_reward_1 = new List<int>();
            List<int> total_skill_reward_2 = new List<int>();
            List<int> total_skill_reward_3 = new List<int>();

            //khen thuong ca nhan
            Document document = new Document(PageSize.A4, 10, 10, 15, 15);
            var page_list_KT_CN = profileModels.getListEmployee_collective_export(text_search, from_date, to_date, arr_departments_id, ref total_all, ref total_skill_reward_1, ref total_skill_reward_2, ref total_skill_reward_3);
            Response.Clear();
            if (type == 1)
            {
                //export to excel
                Response.AddHeader("Content-Disposition", "attachment; filename=khen_thuong_tap_the_" + DateTime.Now.Year + ".xls");
                Response.ContentType = "application/ms-excel";
            }
            else if (type == 2)
            {
                //export to word
                Response.AddHeader("Content-Disposition", "attachment; filename=khen_thuong_tap_the_" + DateTime.Now.Year + ".doc");
                Response.ContentType = "application/ms-word";
            }
            else if (type == 3)
            {
                //export to pdf
                Response.AddHeader("content-disposition", "attachment; filename=khen_thuong_tap_the_" + DateTime.Now.Year + ".pdf");
                Response.ContentType = "application/octet-stream";
                PdfWriter.GetInstance(document, Response.OutputStream);
                document.Open();
            }

            Response.Charset = string.Empty;
            Response.ContentEncoding = Encoding.Unicode;
            Response.BinaryWrite(Encoding.Unicode.GetPreamble());
            StringBuilder sb = new StringBuilder();
            sb.Append("<style>");
            sb.Append("@page Section1 {size:595.45pt 841.7pt; margin:1.03cm 1.25cm 1.0cm 1.25cm;mso-header-margin:.5cm;mso-footer-margin:.5cm;mso-paper-source:0;}");
            sb.Append("div.Section1 {page:Section1;}");
            sb.Append("@page Section2 {size:841.7pt 595.45pt;mso-page-orientation:landscape;margin:1.03cm 1.0cm 1.25cm 1.0cm;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}");
            sb.Append("div.Section2 {page:Section2;}");
            sb.Append("</style>");
            sb.Append("</head>");
            sb.Append("<body>");
            sb.Append("<div class=Section2>");
            sb.Append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"padding:0px;margin:0px;width:27.7cm\" >");
            sb.Append("<tr>");
            sb.Append("<td colspan=\"38\" style=\"text-align:center;font-size:16px;font-weight:bold;\">DANH SÁCH KHEN THƯỞNG ĐỐI VỚI TẬP THỂ<br />Từ:" + (from_date.Value.Day + "/" + from_date.Value.Month + "/" + from_date.Value.Year + " Đến:" + to_date.Value.Day + "/" + to_date.Value.Month + "/" + to_date.Value.Year) + "</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td rowspan=\"3\" style=\"padding-left:5px;padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333\">STT</td>");
            sb.Append("<td  rowspan=\"3\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333;width:1000px\">ĐƠN VỊ</td>");
            //sb.Append("<td  rowspan=\"3\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-top:1px dotted #333;width:250px\">CẤP BẬC<BR/>CHỨC VỤ</td>");
            sb.Append("<td colspan=\"13\" style=\"padding-left: 5px; border-left: 1px dotted #333; border-top: 1px dotted #333; text-align: center;  text-transform: uppercase;\">CÁC HÌNH THỨC KHEN THƯỞNG</td>");
            sb.Append("<td rowspan=\"3\" style=\"padding-left: 5px; border-left: 1px dotted #333; border-top: 1px dotted #333; text-align: center;  text-transform: uppercase;border-bottom: 1px dotted #333;width:150px;\">SỐ,QĐ<br />NGÀY KÝ</td>");
            sb.Append("<td width=\"\" rowspan=\"3\" style=\"padding-left: 5px; border-left: 1px dotted #333; border-top: 1px dotted #333; text-align: center; text-transform: uppercase;border-right:1px dotted #333;border-bottom: 1px dotted #333;width:150px;\">LÝ DO KHEN</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td width=\"312\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center;  border-bottom:1px dotted #333\">Nhà nước</td>");
            sb.Append("<td width=\"312\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center; border-bottom:1px dotted #333\">Chính phủ</td>");
            sb.Append("<td width=\"312\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center;  text-transform: uppercase;border-bottom:1px dotted #333\">BQP</td>");
            sb.Append("<td width=\"312\" rowspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center; border-bottom:1px dotted #333\">Khác</td>");
            sb.Append("<td colspan=\"5\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center;  text-transform: uppercase;\">QUÂN CHỦNG</td>");
            sb.Append("<td colspan=\"4\" style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;text-align: center;  text-transform: uppercase;\">CÔNG TY</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">ĐVQT</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">BK</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">GK</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">ĐVTT</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">Khen khác</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">BK</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">GK</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">ĐVTT</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-top:1px dotted #333;border-bottom:1px dotted #333;width:45px;\">Khen khác</td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td colspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">Tổng:</td>");
            //for (int i = 0; i < total_all.Count; i++)
            //{
                
            //}
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[0] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[1] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[2] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[3] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[9] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[5] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[6] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[10] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[8] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[11] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[12] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[14] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_all[15] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;</td>");
            sb.Append("</tr>");
            var list_skill_reward1 = page_list_KT_CN.Where(p => p.skill_reward == 1).ToList();
            var list_skill_reward2 = page_list_KT_CN.Where(p => p.skill_reward == 2).ToList();
            var list_skill_reward3 = page_list_KT_CN.Where(p => p.skill_reward == 3).ToList();

            sb.Append("<tr>");
            sb.Append("<td colspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">PHẦN I: CHÍNH QUYỀN</td>");
            //for (int i = 0; i < total_skill_reward_1.Count; i++) {
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[i] + "</td>");
            //}
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[0] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[1] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[2] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[3] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[9] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[5] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[6] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[10] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[8] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[11] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[12] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[14] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_1[15] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;</td>");
            sb.Append("</tr>");

            for (int i = 0; i < list_skill_reward1.Count(); i++) //chinh quyen
            {
                var no_reward = list_skill_reward1[i].form_reward;
                var der = "";
                if (list_skill_reward1[i].departments_id != null)
                {
                    der = h_contentModels.getDepartmentsByID(list_skill_reward1[i].departments_id??0).departments_name;
                }
                else
                {
                    der = list_skill_reward1[i].reward_name_group;
                }
                sb.Append("<tr>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">" + (i + 1) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + der + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "1" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "2" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "3" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "4" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "10" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "6" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "7" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "11" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "9" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "12" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "13" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "15" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "16" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + list_skill_reward1[i].reward_number + "<br/>" + String.Format("{0:dd/MM/yyyy}", list_skill_reward1[i].signature_date) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;" + list_skill_reward1[i].descriptions + "</td>");
                sb.Append("</tr>");
            }

            sb.Append("<tr>");
            sb.Append("<td colspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">PHẦN II: TỔ CHỨC ĐẲNG</td>");
            //for (int i = 0; i < total_skill_reward_2.Count; i++)
            //{
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[i] + "</td>");
            //}
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[0] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[1] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[2] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[3] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[9] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[5] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[6] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[10] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[8] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[11] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[12] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[14] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_2[15] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;</td>");
            sb.Append("</tr>");

            for (int i = 0; i < list_skill_reward2.Count(); i++)    //to chuc dang
            {
                var no_reward = list_skill_reward2[i].form_reward;
                var der = "";
                if (list_skill_reward2[i].departments_id != null)
                {
                    der = h_contentModels.getDepartmentsByID(list_skill_reward2[i].departments_id ?? 0).departments_name;
                }
                else
                {
                    der = list_skill_reward2[i].reward_name_group;
                }
                sb.Append("<tr>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">" + (i + 1) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + der + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "1" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "2" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "3" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "4" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "10" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "6" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "7" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "11" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "9" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "12" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "13" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "15" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "16" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + list_skill_reward2[i].reward_number + "<br/>" + String.Format("{0:dd/MM/yyyy}", list_skill_reward2[i].signature_date) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;" + list_skill_reward2[i].descriptions + "</td>");
                sb.Append("</tr>");
            }

            sb.Append("<tr>");
            sb.Append("<td colspan=\"2\" style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">PHẦN III: TỔ CHỨC QUẦN CHÚNG</td>");
            //for (int i = 0; i < total_skill_reward_3.Count; i++)
            //{
            //    sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[i] + "</td>");
            //}
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[0] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[1] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[2] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[3] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[9] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[5] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[6] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[10] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[8] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[11] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[12] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[14] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + total_skill_reward_3[15] + "</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;</td>");
            sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;</td>");
            sb.Append("</tr>");

            for (int i = 0; i < list_skill_reward3.Count(); i++)    //to chuc quan chung
            {
                var no_reward = list_skill_reward3[i].form_reward;
                var der = "";
                if (list_skill_reward3[i].departments_id != null)
                {
                    der = h_contentModels.getDepartmentsByID(list_skill_reward3[i].departments_id ?? 0).departments_name;
                }
                else
                {
                    der = list_skill_reward3[i].reward_name_group;
                }
                sb.Append("<tr>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">" + (i + 1) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + der + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "1" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "2" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "3" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "4" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "10" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "6" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "7" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "11" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "9" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "12" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "13" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "15" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + (no_reward == "16" ? "x" : "&nbsp;") + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;\">&nbsp;" + list_skill_reward3[i].reward_number + "<br/>" + String.Format("{0:dd/MM/yyyy}", list_skill_reward3[i].signature_date) + "</td>");
                sb.Append("<td style=\"padding-left:5px;border-left:1px dotted #333;border-bottom:1px dotted #333;border-right:1px dotted #333;\">&nbsp;" + list_skill_reward3[i].descriptions + "</td>");
                sb.Append("</tr>");
            }

            
            //sb.Append("<tr><td colspan=\"9\" style=\"text-transform:uppercase;padding-top:20px;padding-left:20px;text-align:left;\">Nhân viên thống kê</td></tr>");
            //sb.Append("<tr><td colspan=\"9\" style=\"text-transform:uppercase;padding-top:-20px;position: relative;text-align:right;padding-right:20px;\">Nhân viên chính trị</td></tr>");
            sb.Append("</table>");
            sb.Append("</div>");
            if (type == 3)
            {
                StringReader str = new StringReader(sb.ToString());
                HTMLWorker htmlworker = new HTMLWorker(document);
                htmlworker.Parse(str);
                Response.Flush();
                Response.Close();
                document.Close();
                Response.Write(document);
            }
            else
            {
                Response.Write(sb.ToString());
            }
            Response.End();

            return RedirectToAction("list_KT_TT", new { id = 1, pagesize = pagesize, text_search = text_search, from_date = from_date, to_date = to_date });
        }

        public ActionResult GetAutoCompleted(string id)
        {
            var list = Models.profileModels.GetListEmployeeAutoCompleted(id);
            var data = from s in list select new {  s.full_name };
            return Json(data);
        }

        //Xóa employee
        public ActionResult delete_employee()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        public ActionResult control_delete_employee(int? employee_id,int? id, string text_search, string option_search, int? department_id, byte? employee_status, DateTime? birth_day, int? b_day, int? b_month, int? b_year, string study_level, bool? join_dang, string blood_group, string current_address, int? start_date_insurance, string positions, string house_land_status, string foreign_language, int? date_join)
        {
            if (employee_id != null)
            {
                profileModels.deleteEmployee(employee_id ?? 0);
            }

            ViewBag.result_message = "Xóa hồ sơ thành công";
            ViewBag.result = true;
            ViewBag.redirect = "/vi/profile/profile_search/" + 1 +"/"+text_search+"/"+option_search+"/"+department_id+"/"+employee_status+"/"+b_day+"/"+b_day+"/"+b_month+"/"+b_year+"/"+study_level+"/"+join_dang+"/"+blood_group+"/"+current_address+"/"+start_date_insurance+"/"+positions+"/"+house_land_status+"/"+foreign_language+"/"+date_join;
            return PartialView("../Shared/control_redirect");
        }

        //Xóa hồ sơ y tế
        public ActionResult delete_employee_medical_records()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        public ActionResult control_delete_employee_medical_records(int? employee_id, int? id)
        {
            if (id != null)
            {
                profileModels.deleteEmployeeMedicalByID(id ?? 0);
                ViewBag.result_message = "Xóa hồ sơ sức khỏe #" + id + " thành công.";
                ViewBag.result = true;
            }
            else {
                ViewBag.result_message = "Xóa hồ sơ sức khỏe #" + id + " thất bại.";
                ViewBag.result = false;
            }
            
            ViewBag.redirect = "/vi/profile/detail_profile/" + employee_id;
            return PartialView("../Shared/control_redirect");
        }

            //Xóa hồ sơ thân nhân
        public ActionResult delete_employee_family()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        public ActionResult control_delete_employee_family(int? employee_id, int? id)
        {
            if (id != null)
            {
                profileModels.deleteEmployeeFamilyByID(id ?? 0);
                ViewBag.result_message = "Xóa hồ sơ thân nhân #" + id + " thành công.";
                ViewBag.result = true;
            }
            else {
                ViewBag.result_message = "Xóa hồ sơ thân nhân #" + id + " thất bại.";
                ViewBag.result = false;
            }
            
            ViewBag.redirect = "/vi/profile/detail_profile/" + employee_id;
            return PartialView("../Shared/control_redirect");
        }

        //Xóa hồ sơ bảo hiểm
        public ActionResult delete_employee_insurance()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        public ActionResult control_delete_employee_insurance(int? employee_id, int? id)
        {
            if (id != null)
            {
                profileModels.deleteEmployeeInsuranceByID(id ?? 0);
                ViewBag.result_message = "Xóa hồ sơ bảo hiểm #" + id + " thành công.";
                ViewBag.result = true;
            }
            else
            {
                ViewBag.result_message = "Xóa hồ sơ bảo hiểm #" + id + " thất bại.";
                ViewBag.result = false;
            }

            ViewBag.redirect = "/vi/profile/detail_profile/" + employee_id;
            return PartialView("../Shared/control_redirect");
        }

        //Xóa quá trình đào tạo
        public ActionResult delete_employee_school()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        public ActionResult control_delete_employee_school(int? employee_id, int? id)
        {
            if (id != null)
            {
                profileModels.deleteEmployeeSchoolByID(id ?? 0);
                ViewBag.result_message = "Xóa quá trình đào tạo #" + id + " thành công.";
                ViewBag.result = true;
            }
            else
            {
                ViewBag.result_message = "Xóa quá trình đào tạo #" + id + " thất bại.";
                ViewBag.result = false;
            }

            ViewBag.redirect = "/vi/profile/detail_profile/" + employee_id;
            return PartialView("../Shared/control_redirect");
        }

        //Xóa hồ sơ thông tin visa/passport
        public ActionResult delete_employee_visa_passport()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        public ActionResult control_delete_employee_visa_passport(int? employee_id, int? id)
        {
            if (id != null)
            {
                profileModels.deleteEmployeeVisaPassportByID(id ?? 0);
                ViewBag.result_message = "Xóa thông tin visa/passport #" + id + " thành công.";
                ViewBag.result = true;
            }
            else
            {
                ViewBag.result_message = "Xóa thông tin visa/passport #" + id + " thất bại.";
                ViewBag.result = false;
            }

            ViewBag.redirect = "/vi/profile/detail_profile/" + employee_id;
            return PartialView("../Shared/control_redirect");
        }

        //Xóa thông tin hợp đồng
        public ActionResult delete_contract()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        public ActionResult control_delete_contract(int? employee_id, int? id)
        {
            if (id != null)
            {
                profileModels.deleteContractByID(id ?? 0);
                ViewBag.result_message = "Xóa thông tin hợp đồng #" + id + " thành công.";
                ViewBag.result = true;
            }
            else
            {
                ViewBag.result_message = "Xóa thông tin hợp đồng #" + id + " thất bại.";
                ViewBag.result = false;
            }

            ViewBag.redirect = "/vi/profile/detail_profile/" + employee_id;
            return PartialView("../Shared/control_redirect");
        }

        //Xóa thông tin nghỉ việc
        public ActionResult delete_employee_job_severance()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        public ActionResult control_delete_employee_job_severance(int? employee_id, int? id)
        {
            if (id != null)
            {
                profileModels.deleteEmployeeJobSeveranceByID(id ?? 0);
                ViewBag.result_message = "Xóa thông tin nghỉ việc #" + id + " thành công.";
                ViewBag.result = true;
            }
            else
            {
                ViewBag.result_message = "Xóa thông tin nghỉ việc #" + id + " thất bại.";
                ViewBag.result = false;
            }

            ViewBag.redirect = "/vi/profile/detail_profile/" + employee_id;
            return PartialView("../Shared/control_redirect");
        }

        //Xóa loại đối tượng nhân viên
        public ActionResult delete_object_employee()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        public ActionResult control_delete_object_employee(int? id)
        {
            if (id != null)
            {
                int check= profileModels.deleteObjectEmployeeByID(id ?? 0);
                if (check == 1)
                {
                    ViewBag.result_message = "Xóa đối tượng nhân viên #" + id + " thành công.";
                    ViewBag.result = true;
                }
                else if (check == 0)
                {
                    ViewBag.result_message = "Xóa đối tượng nhân viên #" + id + " thất bại.Hiện đối tượng nhân viên này đã được sử dụng.";
                    ViewBag.result = false;
                }
                
            }
            else
            {
                ViewBag.result_message = "Xóa đối tượng nhân viên #" + id + " thất bại.";
                ViewBag.result = false;
            }

            ViewBag.redirect = "/vi/h_content/list_object_employee/1";
            return PartialView("../Shared/control_redirect");
        }

        //Xóa loại hợp đồng
        public ActionResult delete_type_contract()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        public ActionResult control_delete_type_contract(int? id)
        {
            if (id != null)
            {
                int check = profileModels.deleteTypeContractByID(id ?? 0);
                if (check == 1)
                {
                    ViewBag.result_message = "Xóa loại hợp đồng #" + id + " thành công.";
                    ViewData["result_message"] = "Xóa loại hợp đồng #" + id + " thành công.";
                    ViewBag.result = true;
                }
                else if (check == 0)
                {
                    ViewBag.result_message = "Xóa loại hợp đồng #" + id + " thất bại.Hiện loại hợp đồng này đã được sử dụng.";
                    ViewData["result_message"] = "Xóa loại hợp đồng #" + id + " thất bại.Hiện loại hợp đồng này đã được sử dụng.";
                    ViewBag.result = false;
                }
            }
            else
            {
                ViewBag.result_message = "Xóa loại hợp đồng #" + id + " thất bại.";
                ViewData["result_message"] = "Xóa loại hợp đồng #" + id + " thất bại.";
                ViewBag.result = false;
            }

            ViewBag.redirect = "/vi/h_content/list_type_contract/1";
            return PartialView("../Shared/control_redirect");
        }

        //Xóa loại hình nghỉ phép
        public ActionResult delete_type_leave()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        public ActionResult control_delete_type_leave(int? id)
        {
            if (id != null)
            {
                int check = profileModels.deleteTypeLeaveByID(id ?? 0);
                if (check == 1)
                {
                    ViewBag.result_message = "Xóa loại nghỉ phép #" + id + " thành công.";
                    ViewBag.result = true;
                }
                else if (check == 0)
                {
                    ViewBag.result_message = "Xóa loại nghỉ phép #" + id + " thất bại.Hiện loại nghỉ phép này đã được sử dụng.";
                    ViewBag.result = false;
                }
            }
            else
            {
                ViewBag.result_message = "Xóa loại nghỉ phép #" + id + " thất bại.";
                ViewBag.result = false;
            }

            ViewBag.redirect = "/vi/h_content/list_type_leave/1";
            return PartialView("../Shared/control_redirect");
        }

        //Xóa loại hợp đồng
        public ActionResult delete_type_reward()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        public ActionResult control_delete_type_reward(int? id)
        {
            if (id != null)
            {
                int check = profileModels.deleteTypeRewardByID(id ?? 0);
                if (check == 1)
                {
                    ViewBag.result_message = "Xóa huân huy chương #" + id + " thành công.";
                    ViewBag.result = true;
                }
                else if (check == 0)
                {
                    ViewBag.result_message = "Xóa huân huy chương #" + id + " thất bại.Hiện huân huy chương này đã được sử dụng.";
                    ViewBag.result = false;
                }
            }
            else
            {
                ViewBag.result_message = "Xóa huân huy chương #" + id + " thất bại.";
                ViewBag.result = false;
            }

            ViewBag.redirect = "/vi/h_content/list_type_reward/1";
            return PartialView("../Shared/control_redirect");
        }

        //Xóa thông tin nghỉ việc
        public ActionResult delete_reward()
        {
            InitPage();
            return View();
        }

        [ChildActionOnly]
        public ActionResult control_delete_reward(int? id)
        {
            var old_url = Request.UrlReferrer.ToString();

            if (id != null)
            {
                profileModels.deleteRewardByID(id ?? 0);
                ViewBag.result_message = "Xóa #" + id + " thành công.";
                ViewBag.result = true;
            }
            else
            {
                ViewBag.result_message = "Xóa #" + id + " thất bại.";
                ViewBag.result = false;
            }

            ViewBag.redirect = old_url;
            return PartialView("../Shared/control_redirect");
        }
    }
}
